This process is called respiration. Plants need carbon dioxide to make food during the process of photosynthesis. Nitrogen is used to make living matter. However, animals and plants cannot use it directly from the atmosphere. Plants absorb nitrates from the soil.
Animals obtain nitrogen from the plants they eat becoming part of the animal's body.
Most of the gases were ejected from the earth's crust during long periods of volcanic activity. The atmosphere is separated into distinct layers based on the temperature changes that occur from one layer to the next. The layer of the atmosphere closest to the Earth is the troposphere. This is where we lice and where most weather occurs. As you go higher into the troposphere, the temperature drops.