To make soap, you start with beef fat. If you treat
beef fat with steam you get tallow, a mixture of fats, one of which is
glyceryl tristearate,
a tri-glyceride containing three
stearic acid molecules attached to a glycerine molecule.
When you boil glyceryl tristearate in lye (sodium hydroxide), you get sodium stearate and glycerine. When you remove the glycerine, you get soap.
The sodium end of the molecule attracts water. The long hydrocarbon chain at the other end attracts oils and fats.
sodium stearate: InChI=1/C18H36O2.Na/c1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18(19)20;/h2-17H2,1H3,(H,19,20);/q;+1/p-1/fC18H35O2.Na/q-1;m
stearic acid: InChI=1/C18H36O2/c1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18(19)20/h2-17H2,1H3,(H,19,20)/f/h19H