Oxygen concentrators work on the principle of Pressure-Swing Adsorption. Air is 78% nitrogen, 21% oxygen, and 1% other gasses – neon, argon, carbon dioxide, tiny traces of other things. The trick is to separate the oxygen from the nitrogen, and not worry about the tiny traces of other gasses.
An air compressor pumps ambient air from the room into a tank filled with a material called a molecular sieve, or zeolite. Zeolites are highly porous at a microscopic level, and so have a tremendous amount of surface area packed into a relatively small volume. As the air is pumped into the zeolite tank, nitrogen adsorbs onto the surface of the zeolite, but the oxygen doesn’t (the manufacturer chooses a zeolite that prefers nitrogen).
When it starts to let the pressurized gas out, it’s almost all oxygen. As the pressure drops, more of the nitrogen breaks loose from the zeolite. So it feeds the first gas coming out to the patient, since it’s mostly oxygen, and vent the last of the gas out to the room since it’s mostly nitrogen.
Some designs use two tanks. While one tank is delivering oxygen to the patient, the other tank is venting waste nitrogen to the room. The two tanks take turns.