We present a novel expression for an integrated correlation function of four superconformal primaries in $SU(N)$ $mathcal{N}=4$ SYM. This integrated correlator, which is based on supersymmetric localisation, has been the subject of several recent developments. The correlator is re-expressed as a sum over a two dimensional lattice that is valid for all $N$ and all values of the complex Yang-Mills coupling $tau$. In this form it is manifestly invariant under $SL(2,mathbb{Z})$ Montonen-Olive duality. Furthermore, it satisfies a remarkable Laplace-difference equation that relates the $SU(N)$ to the $SU(N+1)$ and $SU(N-1)$ correlators. For any fixed value of $N$ the correlator is an infinite series of non-holomorphic Eisenstein series, $E(s;tau,bartau)$ with $sin mathbb{Z}$, and rational coefficients. The perturbative expansion of the integrated correlator is asymptotic and the $n$-loop coefficient is a rational multiple of $zeta(2n+1)$. The $n=1$ and $n=2$ terms agree precisely with results determined directly by integrating the expressions in one- and two-loop perturbative SYM. Likewise, the charge-$k$ instanton contributions have an asymptotic, but Borel summable, series of perturbative corrections. The large-$N$ expansion of the correlator with fixed $tau$ is a series in powers of $N^{1/2-ell}$ ($ellin mathbb{Z}$) with coefficients that are rational sums of $E_s$ with $sin mathbb{Z}+1/2$. This gives an all orders derivation of the form of the recently conjectured expansion. We further consider t Hooft large-$N$ Yang-Mills theory. The coefficient of each order can be expanded as a convergent series in $lambda$. For large $lambda$ this becomes an asymptotic series with coefficients that are again rational multiples of odd zeta values. The large-$lambda$ series is not Borel summable, and its resurgent non-perturbative completion is $O(exp(-2sqrt{lambda}))$.