Ever wondered why it's so hard to walk with a cup of coffee without spilling? It just so happens that the human stride has almost exactly the right frequency to drive the natural oscillations of coffee, when the fluid is in a typically sized coffee mug. New research shows that the properties of mugs, legs and liquid conspire to cause spills, most often at some point between your seventh and tenth step.

So says a pair of fluid physicists at the University of California at Santa Barbara (UCSB). They investigated the science of sloshing in a new study published in the journal Physical Review Letters E, and calculated the natural frequency at which coffee sloshes back and forth when held in mugs of a variety of sizes, from a dainty espresso cup to a cappuccino behemoth. They found that a normal human gait moves at nearly the same frequency, so each step amplifies the coffee's heave-ho motion. Stumbling or changing pace — common occurrences when you're low on caffeine — make matters worse by causing chaos in your cup, increasing the chance of a splash over the rim.

But now, there's hope. By modeling the fluid and walking dynamics of the situation, and comparing the math with some real-world walking-with-coffee experiments, the UCSB scientists have uncovered a few tips for bleary-eyed coffee cup carriers.

"Of course, there are ways to control coffee spilling," study co-author Rouslan Krechetnikov told Life's Little Mysteries.

Coffee drinkers often attempt to walk quickly with their cups, as if they might manage to reach their destination before their sloshing java waves reach a critical height. This method is scientifically flawed. It turns out that the faster you walk, the closer your gait comes to the natural sloshing frequency of coffee. To avoid driving the oscillations that lead to a spillage, walk slowly. [Why Does Room-Temperature Coffee Taste So Bad?]

Secondly, watch your cup, not your feet. The researchers found that when study participants focused on their cups, the average number of steps they took before spilling coffee increased greatly. Krechetnikov and his graduate student Hans Mayer, the primary author of the study, suggested two explanations for this result: First, focusing on one's cup tends to engender slower walking, and second, it dampens the noise, or chaotic sloshing, in the cup. Whether focused carrying decreases the amount of noise because we perform "targeted suppression," automatically counteracting the sloshing of the liquid with small flicks of our wrists, or because we simply hold the cup more steadily when we're looking at it, the researchers could not say.

Third, accelerate gradually. If you take off suddenly, a huge coffee wave will build up almost instantly, and it will crash over the rim after just a few steps.

But the best way to prevent coffee spilling might be to find an unusual cup. According to Krechetnikov, ideas from liquid sloshing engineering studies, which historically were done to stabilize fuel tanks inside missiles, indicate three possibilities for spill-free cup designs: "a flexible container to act as a sloshing absorber in suppressing liquid oscillations, a series of annular ring baffles arranged around the inner wall of the container to achieve sloshing suppression, or a different shape cup."