Fats are isolated from plants and animals. The properties such as solubility relate to their chemical structures. Fats are heated with a strong base to convert them into soaps. The fat you use to make soap, reacts with potassium hydroxide to produce a potassium soap, the potassium salt of the fatty acid. One typical animal fat, stearol, reacts with KOH to form potassium stearate, a soap. Most naturally occuring fats produce a mixture of different salts of fatty acids when they are converted to soap.
The potassium soap formed from your fat is converted to a sodium soap by replacing the potassium ions with sodium ions. A large excess of sodium chloride supplies the sodium ion. You may also notice that the potassium soap is softer than the sodium soap. In addition there is a difference in the way the sodium and potassium soaps behave in water.
Both potassium and sodium soaps dissolve in water and are effective as cleaning agents. Each has a polar end to the molecule identified by the negative charge and an end that is primarily carbon and hydrogen. The polar end attracts polar water molecules. The other end, hydrocarbon end, attracts oils and other water insoluble materials like fat or grease. Water is a polar solvent and dissolves polar and ionic molecules. Gasoline is nonpolar and dissolves nonpolar materials such as fat or oil. A way to remember this behavior is the simple axiom; "Like dissolves like."
The nonpolar ends of the molecule associate with the fat, grime or dirt which is also nonpolar, The polar or ionic end of the molecule attracts the water molecules. A spherical structure with the polar portions of the molecule on the surface and the nonpolar parts of the molecule in the center is attracted to the water and carries the non-water-soluble material away with it. This spherical shaped unit of soap and grime is a micelle.
Magnesium and calcium salts of the same fatty acids that make up potassium and sodium soaps are not water soluble. When sodium or potassium soaps are put into water containing calcium and magnesium ions, the cloudyness, scum or curds consist of less soluble calcium and magnesium soaps. To achieve the same washing or cleaning action, more soap must be added.
There are other materials that also have cleaning capacity like soaps. The molecules of detergents also have polar and nonpolar ends. They clean like soaps except that their calcium and magnesium salts are generally more soluble in water than their soap counterparts. In recent years many different detergents have been introduced for use in cleaning. The conversion of one alkyl sulfate into a detergent is shown below.