Soap is made from fat. Heat a fat or an oil with a strong base, sodium hydroxide, and every fat molecule splits into glycerol and three soap molecules.
In lesson 13 you met bases, which pick up H⁺. Sodium hydroxide, NaOH, is a strong one: in water it splits into sodium ions, Na⁺, and hydroxide ions, OH⁻. A fat molecule, as you have seen, is glycerol joined to three fatty acids through ester links. Hot sodium hydroxide solution breaks all three links. Glycerol gets its three -OH groups back, and each fatty acid comes away with a charged -COO⁻ group on its end and a sodium ion beside it. That pair is a soap.
Chemists call this reaction saponification, from sapo, the Latin word for soap. It takes apart the ester links that hold a fat together: the alcohol part comes back as glycerol, and the acid parts come away as soap.
Real fats carry a mix of chains, so real soap is a mix too. Palm oil gives plenty of sodium palmitate. Beef fat adds sodium stearate, from stearic acid's 18-carbon chains, and olive oil gives mostly sodium oleate.
An old craft
People were making soap thousands of years before anyone knew about molecules. Old recipes boil animal fat with lye: water that has soaked through wood ash and picked up its potassium compounds, which are bases. Potassium soaps are soft, and sodium soaps set into hard bars, so most bars of soap today are sodium soaps.
Soap factories collect the glycerol and sell it for hand creams, toothpaste and medicines. Handmade soap keeps its glycerol in the bar.