Pasta water foams up and boils over because of the starch that leaches out of the pasta into the water. Starch changes the surface tension of the water and stops the bubbles forming during boiling from popping easily, so they pile up into a layer of foam.
Plain water barely foams at all, but starchy pasta and a full pot make that foam layer rise fast enough to spill over the rim.
How exactly does starch trigger the foaming?
As pasta hits boiling water it quickly sheds the loose starch sitting on its surface. Those starch molecules form a thin film at the water's surface that lets bubbles hold their air pocket much longer than they normally would.
Bubbles that would usually pop within seconds instead pile up on top of each other because of that film, and the foam keeps rising until it eventually outgrows the pot and spills over.
Why do pot fullness and burner heat matter?
Keeping the water level under two-thirds of the pot's height leaves enough empty space for the foam to rise into. Pots boiled on high heat with the lid left on until the last minute build up foam much faster and are more likely to overflow.
Turning the heat down slows the boiling rate, so bubbles form more slowly and the foam layer does not build up at the same speed.
Does adding salt or oil reduce boil-overs?
Salt raises the boiling point of water only slightly and does not meaningfully cut down on foaming; a thin layer of oil on the surface is what actually helps. The oil film breaks the surface tension holding the bubbles together, letting the foam collapse quickly.
Laying a wooden spoon across the rim of the pot, a trick used in some kitchens, also works by making the rising foam hit the spoon and pop, which buys a little extra time before it overflows.
What is the most practical way to stop it overflowing?
Turning the heat down for a few seconds right as the water nears a boil is usually enough to make the foam collapse and bring it back under control. Leaving the lid a quarter open instead of fully closed also lets steam escape freely and slows down the foam buildup.
Using a wide, shallow pot gives the same amount of water a larger surface area, leaving more room for foam to rise into before it reaches the rim.
Why do whole-wheat or fresh pasta foam differently?
Whole-wheat pasta releases more starch and bran particles into the water than regular pasta, thanks to its bran flecks and higher protein content, which makes the foam both thicker and longer-lasting. Fresh, undried pasta, being higher in egg and flour, adds cloudiness to the water on top of the foaming.
When cooking these types of pasta, keeping the pot a little less full and turning the heat down a notch as it nears a boil helps balance out the higher boil-over risk compared with plain dried pasta.
Gluten-free pasta made from lentil or chickpea flour also tends to shed more starch into the water and foam more; stirring the water at short intervals while cooking this kind of pasta helps keep the foam from building up in one spot and spilling over.
Larger pasta shapes, like penne or fusilli, have more surface area than thin spaghetti, so they release more starch as they cook and build up a slightly thicker layer of foam; that makes watching how full the pot is even more important with these shapes.