As the (English) summer holidays draw to a close, school beckons the young, and the long hot days of July feel like a distant memory, it seems timely to consider ice-cream. The sensory and gustatory pleasures of ice-cream may have originally been concocted by trial and error, but there is a good bit of science that goes into perfecting their appeal.

Everyone knows when ice-cream has not been stored optimally because it gets crunchy due to overlarge ice crystals. But how come something so full of ice can otherwise feel smooth? Why does the air in the ice-cream stay put rather than escaping and the whole structure collapse? And what was Margaret Thatcher's role in the development of soft ice-cream?

Actually that last question can be answered without recourse to science: when she died in the spring the Guardian dispatched the myth that Thatcher was involved in inventing soft ice-cream. She may have had a small bit part in improving some minor part of the components, but soft ice-cream predates her arrival on the J Lyons development team in 1949.

Ice cream is in fact predominantly water: the ice definitely predominates over the "cream". There may, legally, only be as little as 5% milk fat in the mixture plus some additional vegetable fat. The minimum proportion is higher in the US at 10% milk fat, below which it has to be known as ice milk. In the UK, all the fat must be milk fat if the ice-cream is to be described as "dairy", again with that minimum value of 5%.

Around 60% of the composition is simply water, some of which comes from the milk itself. Most of this water freezes to ice, but how the freezing occurs is crucial if the texture of the ice is to be palatable. If the ice crystals grow larger than about 1/100th of a millimetre we can feel it on our tongues as unpleasantly gritty. The freezing process of the mix must be very rapid to ensure the nucleation of a large number of tiny crystals that not only don't grow to exceed this size but are all much of a muchness in size.

Development of grittiness can occur all too easily; poor storage conditions (during transportation, but more commonly in our own freezers) can indeed lead to some of the crystals growing past this critical size. This can happen by a perfectly general process known as Ostwald ripening – by which small crystals of anything tend to shrink and larger crystals grow at their expense – and often arises due to small fluctuations in freezer temperature.

Even a slight temperature rise may mean that the smallest crystals, which are the least stable, start to melt and the water molecules so released can migrate to a nearby larger ice crystal and cause it to grow. This is why you want to start with a population of similarly sized crystals to minimise this effect. Repeated cycles of slight thawing followed by a subsequent drop back in temperature can readily lead to a detectable deterioration in the texture of the ice-cream.

Ice-cream is actually a foam, albeit a frozen one. Many other familiar foods are foams too. The act of whipping cream or egg whites to make a meringue consists of beating air into the liquid. In both of these cases, if you don't beat vigorously and long enough, the foam will collapse once you stop beating and the air will dissipate. All that will be left is a gungy mess.

However, if you persist, the mechanical action of the beating will not only allow air to be incorporated but also cause the proteins present to unravel from their normal globular state. When they have done that they become rather more effective at stabilising the interface between the air and the liquid by reducing its surface energy. This lower surface energy means there is less of a driving force for the interface to collapse to reduce the energy overall; in turn this means an increased stabilisation of the air bubbles.

In ice-cream something similar happens. During the freezing stage of production there is a lot of agitation of the mix to introduce air and this process allows protein and also fat to migrate to the air interface. The presence of these two kinds of molecules at the interface helps to stabilise it so that the bubbles do not collapse. The matrix surrounding the bubbles is of course fairly rigid and full of ice crystals.

Soft ice-cream is softer than regular ice-cream because it has fewer ice crystals present to confer this rigidity. It achieves this in part by having a higher total sugar content. Just like the spreading of salt on roads to prevent freezing in winter, the addition of sugar (quite apart from its contribution to taste) lowers the freezing point of water. The more sugar, the more this temperature is lowered. So, for a given temperature of production and storage, more of the mixture will remain unfrozen when the sugar content is high, giving a soft, creamy texture. I'm afraid it doesn't necessarily mean there is more cream – well you wouldn't want a product that was fattening and full of saturated fats, would you?

When you buy ice-cream you are basically buying air, water and sugar with some other components – the milk fat and the flavours or additions such as nuts – present in fairly low proportions. The more air has been introduced into the mix, the less of anything else you are getting in a tub of a given size. The product will feel (and indeed is) lighter than an expensive brand; it will also feel warmer because there is less ice present. But it should not come as a surprise that paying more for an upmarket brand does actually mean you are getting more ice and "cream" and less air for your money.

None of this should alter the pleasure that a bowl (or cone) of ice-cream can give at the end of a long hot day on the beach. So enjoy before summer sun finally becomes a distant memory.

Athene Donald is a professor of experimental physics at the University of Cambridge and a member of the European Research Council's Scientific Council. She tweets as @AtheneDonald