The solubility of a substance in water depends on balance between its polar non-polar groups in the molecule. This is particularly evident with fatty acids and its derivatives.
The polarity of fatty acid is decreased by ester formation (esters are less soluble in water and more soluble in organic liquids than the parent acid) and increased by salt formation (alkali metal salts are more soluble in water and less soluble in organic solvents than the parent fatty acid).
When the sodium salt of a fatty acid is dissolved in water, e.g. sodium laurate CH3(CH2)10COONa, it is found that the sodium laurate molecules are not present as single molecules but as aggregate of tiny particles which gives the soap solution an opalescent appearance because they are of the size that can scatter light rays.
The hydrophobic hydrocarbon end of the molecule are inward while presented to the water are the carboxylate (hydrophlic) ends. Some of the molecules are ionised making the micelle charged thus repelling each other preventing coagulation and precipitation.
When air is forced into soap solutions, the air bubbles are immediately coated with a layer of molecules, which stabilise them producing a foam. When dirty hands or cloth are washed in soapy water, the soap molecules go to the surface of the oil-water insoluble particles and coat them, the hydrocarbon end of the molecule dissolving in the oil. When the hand or material is rubbed, the oil is rubbed off in small droplets. These oil or dirt droplets become immediately coated and stabilised by the soap molecules. Because the coated particles are small and charged they remain suspended in the water long enough to be washed down the drain.
Calcium and magnesium salts of fatty acids are very insoluble in water, therefore when the soap is used in water containing these ions (hard water), a precipitate of the calcium or magnesium salt of the fatty acid is formed. When all the hardness has been memoved from the water the soap can then carry out its function. The curdy precipitate of the calcium or magnesium salt can be a nuisance when washing.