Hydrocarbons are typically formed from the remains of dinosaurs and old vegetation that have been buried in the earth for a long, long time. When these pools of hydrocarbons are discovered, natural gas and crude oil become available.
An example of how oil and gas are formed underground is the Mount St. Helens volcano eruption in 1980. A heavy layer of ash was quickly deposited over many plants, trees and dead animals. By adding layers of dirt on top and waiting several thousand years, hopefully oil and natural gas will result. Hydrocarbons formed in this manner are often referred to as