Water molecules are polar (they have a positively charged end and a negatively charged end), and they can strongly attract one another.
At the surface of the water, the molecules attract their neighbors beside and below them. The mesh of attracting molecules makes the surface harder to pierce or expand. Pure water doesn't foam when it boils because it's hard to stretch the surface out to make bubbles.
The phenomenon is called "surface tension".
Now drop some pasta in the pot. As it cooks, organic materials (proteins, among other things) are released into the cooking water.
Some of these organics have hydrocarbon parts that don't dissolve in water, and polar parts that do dissolve. They collect on the
surface of the cooking water, with the polar pieces sticking into the water and the hydrocarbon pieces pointing upwards.
The tight mesh of attracting water molecules is disrupted. It becomes much easier to expand the surface into bubbles. As the water boils, foam starts to form on the surface. (Soap makes suds in a similar way.)
Drop a teaspoon of olive oil into the pot. The oil won't mix well with the water, and many tiny oil droplets are formed. The oil droplets at the surface act as bubble breakers. When a bubble of foam starts to form, it encounters an oil droplet. The
part of the bubble that encountered the oil droplet has a much different surface tension than the rest of the bubble, and the stress pops the bubble before it gets very large.
A little dab of butter or vegetable oil will work just as well.
Author: Fred Senese firstname.lastname@example.org