Answer
The main constituent of atmosphere of early earth was carbon dioxide, early earth atmosphere also contains little amount of other gases like ammonia, nitrogen and methane. At that time some of the living organism like bacteria come into existence. these bacteria can prepare their food by gases around them. After that plants and other bacteria come into existence. Plants can now prepare their food by the process of photosynthesis by using sunlight and carbon dioxide. During process of photosynthesis plants absorb carbon dioxide and release oxygen in the atmosphere.
slowly other animals come into existence and these animals eats plants for their food in this way carbon which is present in plants get transferred to the animals body. When these animals die they get buried into the earth with time and they turn into fossil fuel.