The central levels problem asserts that the subgraph of the (2m+1)-dimensional hypercube induced by all bitstrings with at least m+1−ℓ many 1s and at most m+ℓ many 1s, i.e., the vertices in the middle 2ℓ levels, has a Hamilton cycle for any m≥1 and 1≤ℓ≤m+1. This problem was raised independently by Buck and Wiedemann, Savage, Gregor and Škrekovski, and by Shen and Williams, and it is a common generalization of the well-known middle levels problem, namely the case ℓ=1, and classical binary Gray codes, namely the case ℓ=m+1. In this paper we present a general constructive solution of the central levels problem. Our results also imply the existence of optimal cycles through any sequence of ℓ consecutive levels in the n-dimensional hypercube for any n≥1 and 1≤ℓ≤n+1. Moreover, extending an earlier construction by Streib and Trotter, we construct a Hamilton cycle through the n-dimensional hypercube, n≥2, that contains the symmetric chain decomposition constructed by Greene and Kleitman in the 1970s, and we provide a loopless algorithm for computing the corresponding Gray code.