Scientists believe they have come up with a formula for the perfect cup of coffee – it needs fewer beans which are ground more coarsely.

Mathematicians, physicists and materials experts have come together to devise the recipe for a study which has been published in the journal Matter.

A University of Portsmouth spokeswoman said: “They have found that fewer coffee beans, ground more coarsely, are the key to a drink that is cheaper to make, more consistent from shot to shot, and just as strong.”

Mathematician Dr Jamie Foster launched the study after finding that sometimes two shots of espresso, made in seemingly the same way, can sometimes taste different.

His team began by creating a new mathematical theory to describe extraction from a single grain, many millions of which comprise a coffee “bed” which you would find in the basket of an espresso machine.

Dr Foster said: “In order to solve the equations on a realistic coffee bed you would need an army of super computers, so we needed to find a way of simplifying the equations.

“The hard mathematical work was in making these simplifications systematically, in such a way that none of the important detail was lost.”

Dr Foster said: “The conventional wisdom is that if you want a stronger cup of coffee, you should grind your coffee finer.

“This makes sense because the finer the grounds mean that more surface area of coffee bean is exposed to water, which should mean a stronger coffee.”

However, the researchers found that coffee became more “reliable” from cup to cup when using fewer beans ground coarsely.

Dr Foster said: “When beans were ground finely, the particles were so small that in some regions of the bed they clogged up the space where the water should be flowing.

“These clogged sections of the bed are wasted because the water cannot flow through them and access that tasty coffee that you want in your cup.

“If we grind a bit coarser, we can access the whole bed and have a more efficient extraction.

“It’s also cheaper, because when the grind setting is changed, we can use fewer beans and be kinder to the environment.

“Once we found a way to make shots efficiently, we realised that as well as making coffee shots that stayed reliably the same, we were using less coffee.”

The university spokeswoman said: “The new recipes have been trialled in a small US coffee shop over a period of one year and they have reported saving thousands of dollars.

“Estimates indicate that scaling this up to encompass the whole US coffee market could save over 1.1 billion US dollars (£843 million) per year.”

She added that this was the first study to use theoretical modelling to study the science of the perfect espresso, which she said was more complicated than previous studies of drip filter coffee because of the additional pressure.