The cleansing ability of soap is related to its structure. Each soap molecule has two component parts, that is long hydrocarbon chain and the ionic end.
Soaps (once dissociated in water) consists of:
a hydrophobic (water-repelling), non-polar alkyl (hydrocarbon) tail that can interact with dispersion forces with oils. A polar, negatively charged, hydrophilic (water-loving) carboxylate head that can form ion-dipole and dipole-dipole interactions with water, as well as hydrogen bonds.
Both soap and detergent molecules consist of long hydrocarbon chains with one end being polar (that is, with an apparant charge) that causes the end of the molecule to be attracted to water molecules (which are also polar). It’s that polar end on the soap molecule that makes it soluble in water. The hydrocarbon chain isn’t soluble in water, and so when soap dissolves in water it forms microscopically tiny “balls” called “miscelles”.
When a greasy stain is added to a soap-water mixture, the long hydrocarbon chain tails of the soap start to dissolve in the stain. The charged heads remain at the surface of the grease, interacting with the water molecules. These interactions are sue to the fact that ‘like dissolves like’.