All of the oil and gas we use today began as microscopic plants and animals living in the ocean millions of years ago. As these microscopic plants and animals lived, they absorbed energy from the sun, which was stored as carbon molecules in their bodies. When they died, they sank to the bottom of the sea. Over millions of years, layer after layer of sediment and other plants and bacteria were formed.
coal is the same but made from plants.
As they became buried ever deeper, heat and pressure began to rise. The amount of pressure and the degree of heat, along with the type of biomass, determined if the material became oil or natural gas. More heat produced lighter oil. Even higher heat or biomass made predominantly of plant material produced natural gas.
coal oil gas
They are known as fossil fuels. They are found underground but me might run out of them, due to us humans using them so much.