Sodium stearate is one of the main compounds in common soap.
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
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.