There was little or no oxygen in the early atmosphere. The oxygen now in the air was produced by algae and plants through photosynthesis.
In photosynthesis, carbon dioxide and water react to make glucose and oxygen. As a word equation: carbon dioxide + water → glucose + oxygen. The reaction needs light energy, so aquatic plants such as pondweed give off bubbles of oxygen in daylight.
Algae first produced oxygen about 2.7 billion years ago, and soon after this oxygen appeared in the atmosphere. Over the next billion years plants evolved and the percentage of oxygen gradually increased.
Eventually the oxygen level was high enough for animals to evolve.