Mathematicians figured out the perfect espresso

Coffee requires physics and flawless calculations.
Two red cups under espresso machine as it brews coffee
The math appropriately relies on a branch of physics called percolation theory. Credit: Deposit Photos

People love a good cup of coffee, but how do you get a perfect brew? Barring philosophical deep dives into the nature of perfection, an international team of mathematicians and environmental scientists believe that it’s entirely possible to calculate the ideal espresso. Not only that, but they now have the formulas to back it up. The math detailed in their study published in the journal Royal Society Open Science is dense. But the short answer is that’s all about puck size.

Picture the typical espresso machine at your favorite cafe. The small dish into which your friendly barista tamps coffee grounds is called the puck. After inserting it into the machine, hot water flows through the receptacle and molecularly absorbs the beans’ flavor, hue, and (most importantly) caffeine. 

The quality of the final espresso depends on many aspects, including how the grounds are packed, how long water passes through the coffee, and the size of the grounds themselves. It’s always been difficult to accurately predict how a cup of espresso changes based on these variabilities.

To get a better sense of how these different factors interact, researchers ground Tumba beans from Rwanda and Guayacán beans from Colombia into 11 sizes ranging from extremely fine to coarse. They then placed each variant into tubes before using a visualization technology called X-ray computed micro-tomography (XCT). The technique generated 3D maps of each sample’s internal structures, complete with passageways between grains, known as pore spaces, that are impossible to see with the human eye.

Here is where the experiments began to percolate—literally. Using digital flow tests, the team simulated water flow through each sample based on percolation theory, a subset of physics focused on fluid movement between connected spaces. Researchers were particularly interested in understanding how well each sample’s pore space facilitated uninterrupted water routes through the puck. Basically, they brewed a lot of coffee on a computer.

After comparing the results from different coffee grounds, the study’s authors could finally design an equation that calculates how easily water permeates coffee grounds. They also concluded they found the formulas are in “excellent agreement” with their percolation theory, offering a practical way to express coffee ground size and packing as they relate to saturation. 

The main factors are pore space connectivity, grain size, and surface area, as well as how they are packed. All these variables influence how much time water remains in physical contact with the coffee, thereby taking on its flavor profile. More time and contact typically means stronger flavors, and the best way to maximize that is to get as much of the water to flow over the surface area of coffee grounds.

The study’s conclusions are less about altering your personal approach to espresso-making, and more about introducing methods for improving industry equipment. Integrating their formulations into machine settings will allow for more customized grinds, improved filtration, and even better brews. 

In the meantime, go with your gut. If it’s a perfect espresso to you, then that’s all that matters.

 
products on a page that says best of what's new 2025

2025 PopSci Best of What’s New