The water bottle flipping challenge consists of spinning a bottle, partially filled with water, and making it land upright. It is quite a striking phenomenon, since at first sight, it appears rather improbable that a tall rotating bottle could make such a stable landing. Here, we analyze the physics behind the water bottle flip, based on experiments and an analytical model that can be used in the classroom. Our measurements show that the angular velocity of the bottle decreases dramatically, enabling a nearly vertical descent and a successful landing. The reduced rotation is due to an increase in the moment of inertia, caused by the in-flight redistribution of the water mass along the bottle. Experimental and analytical results are compared quantitatively, and we demonstrate how to optimize the chances for a successful landing.