  We analyze modular invariance drawing inspiration from tauberian theorems.
Given a modular invariant partition function with a positive spectral density,
we derive lower and upper bounds on the number of operators within a given
energy interval. They are most revealing at high energies. In this limit we
rigorously derive the Cardy formula for the microcanonical entropy together
with optimal error estimates for various widths of the averaging energy shell.
We identify a new universal contribution to the microcanonical entropy
controlled by the central charge and the width of the shell. We derive an upper
bound on the spacings between Virasoro primaries. Analogous results are
obtained in holographic 2d CFTs. We also study partition functions with a UV
cutoff. Control over error estimates allows us to probe operators beyond the
unity in the modularity condition. We check our results in the 2d Ising model
and the Monster CFT and find perfect agreement.
