I was making pasta, and I noticed the pasta boiling over. I thought about it some more, and I realized I had no idea why this was happening. When the lid is on, the foam rises. When the lid is off, the foam dies back. Clearly there's some surfactant at work allowing bubbles to form, and the bubbles are mostly full of steam. If you remove the lid, they cool and condense down to a tiny size. This article is honestly just not specific enough. Why is the starch important?(It also happens with potatoes) How does a polysaccharide, a hydrophilic molecule, become a surfactant(if indeed it does)? Is it phospholipids from the cells that became pasta? Do starch molecules form a polymer and trap steam underneath like a balloon? Is it some kind of hybrid where bubbles are stabilized by viscosity? What's going on here?
This question on seasoned advice tries to tackle it but gets surface tension wrong(I think) so that makes me a little wary of it. Surfactants like soap reduce the surface tension, allowing bubbles to form by letting water molecules spread out into thin films. They also keep your alveoli in your lungs from collapsing. If starches increased the surface tension, wouldn't that reduce the likelihood of forming bubbles by increasing the energetic penalty? High surface tension materials act like mercury.
This answer is all over the internet but doesn't make any sense to me. You need less surface tension for bubbles, surely?
If it's just phospholipids acting as detergent, could I 'boil over' pasta in cold water with a whisk? (I tried this, you can't.)
I considered putting this on seasoned advice, but I'm not interested in how to prevent boil-over(or really any practical results), and the supplied answer there lacks scientific rigor.

The starch forms a loosely bonded network that traps water vapor and air into a foamy mass, which expands rapidly as it heats up.

Starch is made of glucose polymers (amylopectin is one of them, shown here):



Some of the chains are branched, some are linear, but they all have $\ce{-OH}$ groups which can form hydrogen bonds with each other.

Let's follow some starch molecules through the process and see what happens. In the beginning, the starch is dehydrated and tightly compacted - the chains are lined up in nice orderly structures with no water or air between them, maximizing the hydrogen bonds between starch polymers:



As the water heats up (or as you let the pasta soak), water molecules begin to "invade" the tightly packed polymer chains, forming their own hydrogen bonds with the starch:



Soon, the polymer chains are completely surrounded by water, and are free to move in solution (they have dissolved):



However, the water/starch solution is not completely uniform. In the middle of the pot of water, the concentration of starch is low compared to water. There are lots and lots of water molecules available to surround the starch chains and to keep them apart. Near the surface, when the water is boiling, the water molecules escape as vapor. This means that near the surface, the local concentration of starch increases. It increases so much as the water continues to boil, that the starch can collapse back in on itself and hydrogen bond to other starch molecules again. However, this time the orderly structure is broken and there is too much thermal motion to line up. Instead, they form a loosely packed network of molecules connected by hydrogen bonds and surrounding little pockets of water and air (bubbles):



This network is very weak, but it is strong enough to temporarily trap the air as it expands due to heating - thus, the bubbles puff up and a rapidly growing foam forms. Since they are very weak, it doesn't take much to disrupt them. Some oil in the water will inhibit the bubbles from breaking the surface as easily, and a wooden spoon across the top will break the network mechanically as soon as it touches it.

Many biomolecules will form these types of networks under different conditions. For example, gelatin is a protein (amino acid polymer) that will form elastic hydrogen-bonded networks in hot water. As the gelatin-water mixture cools, the gel solidifies, trapping the water inside to form what is called a sol-gel, or more specifically, a hydrogel. 

Gluten in wheat is another example, although in this case the bonds are disulfide bonds. Gluten networks are stronger than hydrogen-bonded polysaccharide networks, and are responsible for the elasticity of bread (and of pasta).

DISCLAIMER:


pictures are not remotely to scale, starch is usually several hundred glucose monomers long, and the relative size of the molecules and atoms isn't shown.
there aren't nearly enough water molecules - in reality there would be too many to be able to see the polymer (1,000's).
the starch molecules aren't "twisty" enough or showing things like branching - the real network structure and conformations in solution would be much more complicated.


But, hopefully you get the idea!
