Three conditions must be present for oil reservoirs to form:
* A source rock rich in hydrocarbon material buried deeply enough for subterranean heat to cook it into oil,
* A porous and permeable reservoir rock where it can accumulate,
* A caprock (seal) or other mechanism to prevent the oil from escaping to the surface. Within these reservoirs, fluids will typically organize themselves like a three-layer cake with a layer of water below the oil layer and a layer of gas above it, although the different layers vary in size between reservoirs. Because most hydrocarbons are less dense than rock or water, they often migrate upward through adjacent rock layers until either reaching the surface or becoming trapped within porous rocks (known as reservoirs) by impermeable rocks above. However, the process is influenced by underground water flows, causing oil to migrate hundreds of kilometres horizontally or even short distances downward before becoming trapped in a reservoir. When hydrocarbons are concentrated in a trap, an oil field forms, from which the liquid can be extracted by drilling and pumping.
The reactions that produce oil and natural gas are often modeled as first order breakdown reactions, where hydrocarbons are broken down to oil and natural gas by a set of parallel reactions, and oil eventually breaks down to natural gas by another set of reactions. The latter set is regularly used in petrochemical plants and oil refineries.
Petroleum has mostly been recovered by oil drilling (natural petroleum springs are rare). Drilling is carried out after studies of structural geology (at the reservoir scale), sedimentary basin analysis, and reservoir characterisation (mainly in terms of the porosity and permeability of geologic reservoir structures). Wells are drilled into oil reservoirs to extract the crude oil. "Natural lift" production methods that rely on the natural reservoir pressure to force the oil to the surface are usually sufficient for a while after reservoirs are first tapped. In some reservoirs, such as in the Middle East, the natural pressure is sufficient over a long time. The natural pressure in most reservoirs, however, eventually dissipates. Then the oil must be extracted using "artificial lift" means. Over time, these "primary" methods become less effective and "secondary" production methods may be used. A common secondary method is "waterflood" or injection of water into the reservoir to increase pressure and force the oil to the drilled shaft or "wellbore." Eventually "tertiary" or "enhanced" oil recovery methods may be used to increase the oil's flow characteristics by injecting steam, carbon dioxide and other gases or chemicals into the reservoir. In the United States, primary production methods account for less than 40 percent of the oil produced on a daily basis, secondary methods account for about half, and tertiary recovery the remaining 10 percent. Extracting oil (or "bitumen") from oil/tar sand and oil shale deposits requires mining the sand or shale and heating it in a vessel or retort, or using "in-situ" methods of injecting heated liquids into the deposit and then pumping the liquid back out saturated with oil.