At the heart of both the carbon and nitrogen cycles are microorganisms such as bacteria. These key nutrients pass from plants to animals through ingestion and digestion (eating!) in a very straightforward way, but what happens after those organisms die is a far more interesting tale.
Plants take up atmospheric CO2 to photosynthesise: the carbon in CO2 is transferred to the carbon in glucose.
This carbon in glucose is either respired by the plant itself and released as CO2 back into the atmosphere, or is passed on to animals eating the plants. Here, it either gets released back as CO2 in respiration or becomes manure.
But eventually, all the carbon not quickly released back into the atmosphere as CO2 will end up in the ground, for microorganisms to decompose.
Saprobiotic* bacteria can assimilate organic waste (all of which is made of carbon) and use it for their own respiratory needs. This in turn produces CO2 or methane gas, depending on species. Both gases get released into the atmosphere from where plants take CO2 up again for photosynthesis, restarting the cycle.
*Externally digesting… kinda like someone chewing your food for you.
Nitrogen is also a key element that makes up DNA and proteins. It is present in its cycle in various forms including nitrogen gas which makes up the biggest part of the air in the Earth’s atmosphere, ammonia, nitrites and nitrates in the soil, and of course in all the waste products of living things.
Microorganisms also play a key role here in decomposing these materials and producing the intermediary nitrates. Following a series of reactions, nitrogen from these sources ends up back into the atmosphere.