Dear Student,
With oxygen from the air the food can get "oxidized". Oxygen is necessary for the decomposition / rotting process hence to remove the oxygen and preserve the food from spoilage. And as Nitrogen is unreactive and does not support the decomposition so the food will remain in better condition for a longer time. Nitrogen is often added to packages of chips/snacks/etc. to "fill" the bag and prevent breakage, while not encouraging spoilage due to oxidation.
Regards