Like Molecules Attract
Both oil and water are made up of molecules. However, the molecules only want to be with similar molecules, so when poured together, oil and water separate to stick with their own kind. Water molecules move toward other water molecules, just like oil molecules do. Part of the reason that these two molecules refuse to mix involves positive and negative charges.
Polar Versus Nonpolar
Water molecules are polar, which means that they possess both positive and negative charges. Water molecules attract to one another and they also attract other polar molecules. However, oil is a non-polar molecule, which means there is no separation of charges so they can't attract a polar molecule. Nonpolar molecules equally share electrons between two different atoms. Unless you change the chemistry severely or add more molecules to create a polar bond, oil refuses to mix with water.
Mixing the Two
When you mix oil and water, groups of oil molecules form on the surface of the water. Oil is lighter than water, so these molecules always float to the top. An oil slick forms on the surface of water, but you easily break up the top layer of oil by shaking the water and oil. The molecules, however, quickly regroup according to their respective polarity -- oil with oil and water with water.
Soaking It Up
One way exists to force oil and water to mix together. Chemists use an emulsifier, a molecule that attracts most other molecules, such as soap. A soap molecule attracts both polar and nonpolar molecules, including oil and water. For example, when you wash greasy dishes, you can try to wash off the oiliness with water, but you need soap to really get your hands clean. The oil mixes with the water and soap, removing the residue from your skin. Egg yolks are another emulsifier. In making mayonnaise, egg yolks serve to combine the oil and vinegar, two molecules that usually do not mix.