In simulations and experiments, we study the drying of films containing mixtures of large and small colloidal particles in water. During drying, the mixture stratifies into a layer of the larger particles at the bottom with a layer of the smaller particles on top. We developed a model to show that a gradient in osmotic pressure, which develops dynamically during drying, is responsible for the segregation mechanism behind stratification.