Double-diffusive instabilities are often invoked to explain enhanced transport in a stably-stratified fluid region. The most-studied natural manifestation of this process, fingering convection, commonly occurs in the ocean's thermocline. There, transport can be further enhanced by the formation of “thermohaline staircases,” stacks of deep well-mixed convective layers separated by thin stably-stratified interfaces, whose origin and dynamics have remained controversial. We investigate the evolution of this type of double-diffusive system using mean-field hydrodynamics and 3D numerical simulations. Our findings finally provide a clear picture of the sequence of events resulting in the formation of layers, unifying previously contentious hypotheses. Furthermore, they supply quantitative predictions for the necessary conditions and timescales for layer formation, and guidance for the applicability of these ideas to other systems.