In this paper we study high-dimensional time series that have the generalized dynamic factor structure. We develop a test of the null of k0 factors against the alternative that the number of factors is larger than k0 but no larger than k1>k0. Our test statistic equals maxk0<kk1(γk−γk+1)(γk+1−γk+2), where γi is the ith largest eigenvalue of the smoothed periodogram estimate of the spectral density matrix of data at a prespecified frequency. We describe the asymptotic distribution of the statistic, as the dimensionality and the number of observations rise, as a function of the Tracy–Widom distribution and tabulate the critical values of the test. As an application, we test different hypotheses about the number of dynamic factors in macroeconomic time series and about the number of dynamic factors driving excess stock returns.