Detergents that can be degraded by bacteria are called biodegradable detergents. Such detergents have straight hydrocarbon chains.
For example: Sodium Lauryl sulphate.
Detergents that cannot be degraded have highly branched hydrocarbon chains.
For example: Sodium - 4- (1, 3, 5,7 - tetra methyl octyl) benzene sulphonate.
Soap molecules form micelles around an oil droplet (dirt) in such a way that the hydrophobic parts of the stearate ions attach themselves to the oil droplet and the hydrophilic parts project outside the oil droplet. Due to the polar nature of the hydrophilic parts, the stearate ions (along with the dirt) are pulled into water, thereby removing the dirt from the cloth.