Animals get nitrogen from the plants and animals they eat. The plants take nitrogen from the soil by the help of nitrogen fixing bacteria and then these plants are eaten by the animals and they get nitrogen in this way.
The carnivores animals feed on small animals that contain nitrogen.When they die the nitrogen gets back into the soil to be used again by the plants.
In this way the animals get nitrogen by eating the plants and animals present in the environment.