The oxygen level throughout the movie remained at 20%. Why?
He had a machine called an oxygenator in the Hab. Throughout the book, a lot happens with this machine and it is the reason he has to cut a hole in the top of one of the Rovers to carry it. He brings it with him to the lander (Ares IV) site which explains the oxygen during that long drive and there.
It should be noted that the book focuses a lot on the fact that if you breathe in a sealed environment, you will die of carbon dioxide poisoning long before you can deplete the oxygen. Removal of CO2, therefore, is more important on the whole.
He has a large but limited amount of disposable filters which can trap CO2, and greatly extend the amount of time he can breathe a limited quantity of air. It doesn't replenish oxygen though so he still needs to get oxygen from somewhere.
The oxygenator works by cooling air to very low temperatures and decent pressure. It then separates gases based on their condensation/sublimation temperatures. This is how compressed gases are produced and is probably the most effective way to do it in bulk.
In real-life there are also filtration systems which can separate gasses as gasses (this is often used for putting N2 in bags of chips for example). On the ISS, they perform electrolysis to separate water into oxygen and hydrogen but that would make no sense on Mars as he has very limited water supplies.
As explained in the book, between the oxygenator and the MAV fuel plant and the thin but definitely present Martian atmosphere, Watney had an abundance of oxygen - as long as all the equipment kept working.
The Martian, Ch. 1:
In the Hab, we had the Oxygenator, a large piece of equipment that could break CO2 apart and give the oxygen back. But the spacesuits had to be portable, so they used a simple chemical absorption process with expendable filters. I’d been asleep long enough that my filters were useless.
The Martian, Ch. 2:
I ran a full diagnostic on the Oxygenator. Twice. It’s perfect. If anything goes wrong with it, there is a short-term spare I can use. But it’s solely for emergency use while repairing the main one. The spare doesn’t actually pull CO2 apart and recapture the oxygen. It just absorbs the CO2 the same way the spacesuits do. It’s intended to last 5 days before it saturates the filters, which means 30 days for me (just one person breathing, instead of six). So there’s some insurance there.
The Water Reclaimer is working fine, too. The bad news is there’s no backup. If it stops working, I’ll be drinking reserve water while I rig up a primitive distillery to boil piss. Also, I’ll lose half a liter of water per day to breathing until the humidity in the Hab reaches its maximum and water starts condensing on every surface. Then I’ll be licking the walls. Yay. Anyway, for now, no problems with the Water Reclaimer.
So yeah. Food, water, shelter all taken care of.
The Martian, Ch. 3:
But oxygen’s easier to find on Mars than you might think. The atmosphere is 98% CO2. And I happen to have a machine whose sole purpose is liberating oxygen from CO2. Yay Oxygenator!
One problem: The atmosphere is very thin. About 1/90th the pressure on Earth. So it’s hard to collect. Getting air from outside to inside is nearly impossible. The whole purpose of the Hab is to keep that sort of thing from happening. The tiny amount of Martian atmosphere that enters when I use an airlock is laughable.
That’s where the MAV fuel plant comes in.
My crewmates took the MAV away weeks ago. But the bottom half of it stayed behind. NASA is not in the habit of putting unnecessary shit in to orbit. It left the landing gear, ingress ramp, and fuel plant behind. Remember how the MAV made its own fuel with help from the Martian atmosphere? Step one of that is to collect CO2 and store it in a high pressure vessel. Once I get that hooked up to the Hab’s power, it’ll give me half a liter of liquid CO2 per hour, indefinitely. After 5 days it’ll have made 125L of CO2, which will make 125L of O2 after I feed it through the Oxygenator.