Oil didn't just happen; it took quite a long time for oil to develop below the Earth's surface. The first step in the process happened somewhere between 10 million and 600 million years ago (give or take a few years). At this time, tiny plants and animals (plankton) lived and died in the vast, ancient seas. As these organisms died, they sank to the bottom of the sea, mixing with the sand and mud there. Since these plants and animals were dead, they began to decay. As their organic material decayed, it settled among different sedimentary layers. None of these sedimentary layers had any oxygen, so the microorganisms that broke down the remains transformed them into carbon-rich compounds.
These carbon-rich compounds remained organic material, which continued to mix with sediment to create fine-grained shale, or source rock. This process continued for millions of years, with more and more layers of sediment and source rock piling on top of each other. These continuous layers in turn exerted incredible pressure and heat on the layers and rocks beneath them. This heat and pressure is what ultimately distilled the carbon-rich compounds stuck in the source rocks into crude oil and natural gas.
Once in the form of crude oil or natural gas, the substance would ooze away from the source rock where it would gather in the thicker and more porous rocks, like limestone and sandstone. Also called reservoir rocks because they hold the crude oil, such rocks were able to hold on to the crude oil or natural gas in them because the Earth's movements pushed layers of impermeable rocks, like marble or granite, above them. The Earth's movements, which helped keep the crude oil and natural gas trapped, called folding, where inward movement pushes rock upwards into a fold; faults, where rocks crack and one side moves up or down; and pinching out, where impermeable rock pushes up into reservoir rock.