When Earth formed 4.6 billion years ago from a hot mix of gases and solids, it had almost no atmosphere. The surface was molten. As Earth cooled, an atmosphere formed mainly from gases spewed from volcanoes such as CO2 and N2.
CO2 is reduced as it is absorbed by plants for photosynthesis. Levels of CO2 reduces as it is absorbed by the sea
The animals who eat these plants then get some of the carbon dioxide transferred into their tissue
When the animals flesh and skin decays and rots away the carbon dioxide the was transferred in their tissue is transferred to the bones.
The bones are covered in layer of sand and silt and eventually form fossil fuels
Humans then dig into the ground and find these fossil fuels are burn them.