A classical theorem proved in 1942 by I.J. Schoenberg describes all real-valued functions that preserve positivity when applied entrywise to positive semidefinite matrices of arbitrary size; such functions are necessarily analytic with non-negative Taylor coefficients. Despite the great deal of interest generated by this theorem, a characterization of functions preserving positivity for matrices of fixed dimension is not known. In this paper, we provide a complete description of polynomials of degree $N$ that preserve positivity when applied entrywise to matrices of dimension $N$. This is the key step for us then to obtain negative lower bounds on the coefficients of analytic functions so that these functions preserve positivity in a prescribed dimension. The proof of the main technical inequality is representation theoretic, and employs the theory of Schur polynomials. Interpreted in the context of linear pencils of matrices, our main results provide a closed-form expression for the lowest critical value, revealing at the same time an unexpected spectral discontinuity phenomenon. Tight linear matrix inequalities for Hadamard powers of matrices and a sharp asymptotic bound for the matrix-cube problem involving Hadamard powers are obtained as applications. Positivity preservers are also naturally interpreted as solutions of a variational inequality involving generalized Rayleigh quotients. This optimization approach leads to a novel description of the simultaneous kernels of Hadamard powers, and a family of stratifications of the cone of positive semidefinite matrices.