Underground oil is found in porous sedimentary rocks, as a result of millions of years of decay of prehistoric vegetable matter under high pressure, from the weight of sediments and rocks accumulated above the deposits over millions of year.
After seismic surveys, drilling begins in the optimal position to the depth of the oil-bearing strata. When the production wells have been drilled and lined with a protective casing, a perforating gun is lowered down them to drive explosive charges through the casing and cement and into the rock beyond, which loosens the rock enough to facilitate the oil flowing into the wells. Usually the pressure from the rocks above is enough to push the underground oil reserves into the well.
As oil is extracted, pressure may be maintained by injecting water (steam) or gas into the reservoir rock to displace the oil towards the production wells. Even with the help of modern techniques, however, such as electrical and mechanical pumps, it is seldom possible to extract more than 30% to 50% of the oil in a field.
Once the oil is out of the ground, it is refined into several grades and by-products. In the early days of oil production (in the late 1800s) when the key product from crude oil was kerosene for lighting, gasoline was a wasted by-product. Nowadays, gasoline is the major product, as well as natural gas for home heating, with by-products ranging from motor oil, sulfur, fertilizers, and compounds necessary for the manufacture of plastics and other synthetic substances.