Water and oil do not mix because of their molecular properties. On one hand, water has a slight positive charge and is attracted to atoms and molecules with a negative charge. Oil is an electrically neutral substance and has no affinity for water. Water molecules also have high surface tension and are strongly attracted to each other. A surface-active intermediary is necessary for water and oil to mix.
Since water and oil are naturally immiscible, water alone cannot clean greasy surfaces. Detergents, which are comprised of surfactants, perform two functions that help water and oil mix. Because water is a polar molecule, there is a net positive charge on its hydrogen atoms and a net negative charge on its oxygen atoms. Therefore, the positive side of the surfactant is repelled by water and the negative side is attracted to water.
The surfactant molecule is more liberal than the water molecule, and it reduces its surface tension while bringing the oil and water together. The end of the surfactant molecule that attracts water attaches to the water molecule, whereas the end that repels water attaches to the oil molecule.
The resulting mixture is an emulsion in which tiny drops of oil are suspended in the water-detergent mixture, where they can be washed away.