Oil and natural gas originate from the remains of microscopic plants and animals that lived in the ocean millions of years ago, which absorbed energy from the sun. This energy was stored as carbon molecules in their bodies that sank to the bottom of the sea when they died.
Over millions of years, these sediments and other plants and bacteria formed layers of an organic polymer called kerogen.
Sand, clay and other minerals were buried with kerogen over geological time and eventually became kerogen-rich sedimentary rocks. As the sedimentary rocks reached deeper, the heat and pressure began to increase. The amount of pressure and the degree of heat they received is what determined whether the material turned into oil or natural gas.