Cleaning action of soap has been explained with the help of the image below:
Soaps are molecules in which the two ends have differing properties, one is hydrophilic, that is it dissolves in water, while the other end is hydrophobic, that is it dissolves in hydrocarbons. When soap is at the surface of water, the hydrophobic ‘tail’ of soap will not be soluble in water and the soap will align along the surface of water with the ionic end in water and the hydrocarbon ‘tail’ protruding out of water.

Inside water, these molecules have a unique orientation that keeps the hydrocarbon portion inside the water. This is achieved by forming clusters of molecules in which the hydrophobic tails are in the interior of the cluster and the ionic ends are on the surface of the cluster. This formation is called a micelle. When a dirty cloth is put in water containing dissolved soap, then soap in the form of a micelle is able to clean. The hydrocarbon ends of the soap attach to the oily dirt particles and entrap them at the centre of the micelle. the ionic ends in the micelles remain attached to water. When the dirty cloth is agitated in soap solution, the oily dirt particles entrapped by soap micelles get dispersed in water and the cloth gets cleaned.