Each molecule has two distinct parts - a water soluble end, and a water repellant end. The water repellant ends either bond to or around the molecule being cleaned leaving the water soluble ends to remain soluble. This allows the 'dirty' molecules to be dissolved in water and washed away. Sort of.