You have no doubt already heard that it is difficult to breathe at great heights. This is because the higher you get, when climbing a mountain for example, the lower the air pressure gets. Air pressure is practically the weight of the air above us.
Higher up there is less air above you and therefore there is less air pressure. However, the oxygen pressure also decreases and the lungs can hold less oxygen; so breathing becomes more and more difficult.
Nowadays, our planes fly at heights of more than ten kilometres, which is much higher than the biggest and highest mountain on earth. So, how can we still breathe on the plane?
First of all, modern planes are equipped with pressurised cabins. These are sealed air chambers in which the pressure can be artificially increased or decreased. So the pressure for us humans in these lofty heights is adjusted so that we can breathe normally. Over time, the air wears out of course and the oxygen is used up. Therefore, new air must be provided and this comes from inside the engines. In the engines there are a number of compressors. These machines press gases together ("compresses" them) so that they take up less space. In the case of a plane they suck the thin air from the outside and compress it.
Part of this compressed air is used for the breathing air in the cabin. As this air is very hot, it is first cooled and then fed through valves in the air conditioning. In modern planes, this is done automatically by a computer. From there the air passes into a mixing chamber, where it is mixed with a portion of the already used cabin air. The finished air mixture is then directed into the cabin and provides the passengers with new oxygen.
By the way: the cabins of larger planes are divided into several "climate zones". The air in the different zones can be adjusted separately. The circulating air from the cabin is repeatedly filtered to keep it clean. For example, the air exchange in an Airbus A340-300 is carried out every two minutes - this corresponds to 30 times an hour!