Hydrocarbons do not dissolve in water because they are nonpolar compounds and water is a polar solvent. The general solubility rule is "like dissolves like," meaning polar solvents dissolve polar solutes and nonpolar solvents dissolve nonpolar solutes. Removing one or more hydrogen atoms from the hydrocarbon so it forms a multiple bond or replacing a hydrogen atom with another functional group increases the polarity and solubility of the organic compound.
While water and hydrocarbons appear to mix initially, allowing the container to remain undisturbed results in the formation of two liquid layers. One is water and the other is the hydrocarbon. The densities of water and the hydrocarbon determine which floats on top of the other. Scientists use the word immiscible to describe this phenomenon.
For a solution to form, a molecule of the water must attract a molecule of the hydrocarbon with a greater strength than the hydrocarbon exhibits for the same molecule. With the polar and nonpolar mix, this does not occur and the two distinct layers form. The concept of like dissolves like has practical applications. In the laundry room, detergents dissolve in water, decreasing its polarity and dissolving oils for better cleaning. However, applying a prewash solution, containing slightly polar organic solvents that dissolve in water while retaining enough nonpolar characteristics to dissolve grease stains, offers a more effective method of stain removal.