Oil and natural gas typically form in sedimentary rocks. When carbon-rich organic material, like leaves, are deposited terrestrially in water with a low oxygen content (stagnant water), it may not fully decay. Think about swamps and bogs! If this happens and sediment is deposited on top, a coal bed can form. Many of the largest coal beds in the world are a result of huge Devonian and Carboniferous swamps . Similarly, oil and gas are formed when organic material is deposited in deep marine sediments. In marine deposits the organic material is mostly phytoplankton, microscopic animals that convert sunlightinto energy. When they die and settle to the ocean floor some of this energy remains in the form of carbon molecules in their bodies. Other elements that settle to the ocean floor are nitrogen,oxygen, and hydrogen. All of these molecules mix with very fine grained sediment and form an organic-rich ‘ooze’. As sediments continue to be deposited, burying the ooze (remember burial is vital to preservation!), the weight of the overlying sediment will cause an increase in temperature and pressure, which will in turn lithify the ooze. It also provides enough energy for the carbon and hydrogen molecules to bond, forming hydrocarbons: oil or natural gas. The temperature,pressure, and type of organic material determine whether oil or gas is formed. Relatively lower temperatures and pressures form oil, while higher temperatures and pressures form gas.

Pore space and permeability image.
Trap/reservoir etc image.
Short video showing phytoplankton to reservoir rock?