A soap molecule is made up of two chemically distinct parts that interact with water in different ways. It has one polar end with a short head carboxylate group (\(-COONa\)) and one non-polar end with a long tail made of the hydrocarbon chain.
The hydrophilic and hydrophobic end
The polar end is hydrophilic (water-loving) in nature, and it is drawn to water.
The non-polar end is hydrophobic (hates water) in nature, and it is attracted to dirt or oil on the cloth but not to water.
Cleansing action
As a result, the hydrophobic part of the soap molecule traps the dirt while the hydrophilic part makes the entire molecule water-soluble.
 \(3d\) image of the micelles
When soap or detergent is dissolved in water, the molecules form clusters known as 'micelles'.
Their long hydrocarbon chains bind to the oil and dirt. As a result, the dirt is surrounded by the non-polar end of the soap molecules.
The micelles are water-soluble because of the charged carboxylate end of the soap molecules. As a result, the soap washes away the dirt.
The above images depict micelles cleaning dirt from the scalp and hair. Similarly, this type of cleansing action occurs in shampoo, floor cleaners, and so on.