We’ve seen that soap is a fatty acid chain with the acid end neutralized by sodium. Sodium has eleven electrons, and the one outer electron is only loosely held by the atom. Its other ten electrons are held very tightly by the sodium atom’s nucleus.
Sodium loses its outer electron to the oxygen atom in the fatty acid, which pulls strongly on electrons. The oxygen becomes negatively charged, the sodium is left positively charged, and opposites attract, so the sodium hangs around the fatty acid.
Right after sodium with its eleven electrons comes magnesium with twelve electrons. Magnesium has two outer electrons it can lose to fatty acids. So when magnesium reacts with soap, it hangs onto two fatty acids instead of one.
Soap scum – magnesium distearate
Unfortunately for people who use soap, this molecule does not dissolve in water, and forms what we call soap scum. The scum sticks to clothes and hands, and forms a dirty ring in the bathtub. Calcium also has two outer electrons, and it does the same thing. If your water contains too much magnesium and calcium, we say it is hard water.
Chemists found out a long time ago that they could change the acid part of the fatty acid from a carboxylic acid to a sulfuric acid, and the result was a molecule that could dissolve in hard water, so it doesn’t form soap scum.
Sodium lauryl sulfate – the detergent in shampoo
Molecules like these are called detergents. We use them to wash our clothes, and we use them to wash our hair. Some bars of “soap” are actually detergent bars.