A soap molecule is a sodium or potassium salt of long-chain carboxylic acid.It is composed of two sections, i.e., a long hydrocarbon tail and a negatively charged head. The hydrocarbon tail is hydrophobic, i.e., insoluble in water and repelled by water while the polar end is soluble in water and hydrophilic in nature. When soap is applied on a wet dirty surface, the polar end of the soap molecule dissolves in water while the nonpolar end attaches it to the dirt molecule, as dirt is non-polar in nature. This results in the formation of spherical clusters called Micelles. In micelle, the hydrophobic tails are in the interior of the cluster while the ionic ends are on the surface of the cluster. Due to ion-ion repulsion, the micelle stays in the solution as a colloid and does not come together to form a precipitate. Thus, an emulsion is formed which helps to dissolve dirt in water and it is finally washed with running water.
Soap in hard water does not perform because of the presence of Magnesium and Iron in hard water.