Soap, water and oil are all made up of molecules. Some molecules are hydrophillic, (hydro=water and philic=loving) these molecules are attracted to water. Some molecules are hydrophobic, (hydro=water and phobic=fearing), they are repelled by water.
Molecules that readily mix with water are hydrophilic. Molecules that readily mix with oil are hydrophobic. Since we all know that water and oil do not mix, then we also know that hydrophilic and hydrophobic compounds do not mix.
Most of what we call dirt is grease or oil which will not come off with just water. This is because oil and grease are non-polar, which means they will not dissolve in the water.
Soap can mix with both water and with oil. Why? The soap molecule has two different ends, one that is hydrophilic (polar head) that binds with water and the other that is hydrophobic (non-polar hydrocarbon tail) that binds with grease and oil.
When greasy dirt is mixed with soapy water, the soap molecules arrange themselves into tiny clusters called micelles.
The water-loving (hydrophilic) part of the soap molecules sticks to the water and points outwards, forming the outer surface of the micelle.
The oil-loving (hydrophobic) parts stick to the oil and trap oil in the center where it can’t come into contact with the water. With the oil tucked safely in the center, the micelle is soluble in water. As the soapy water is rinsed away the greasy dirt goes along with it.