The upper atmosphere is not a friendly place. It's cold up there, real cold, -40C cold. The air is also much too thin to breath. In order to fly at high altitude we need to keep the aircraft cabin heated and pressurized. So let's take a look at what's keeping us alive up at 40,000 feet.
An airliner is not completely sealed off like a submarine. There is always air going in and there's always air going out. By controlling how much air we let out at a time, we can keep the insides under pressure.
So where does the air come in from? It originates at the engines. We "bleed" some air off the compressor stage of the engine. Since this is at the front of the engine, this is just normal air - it doesn't have any exhaust in it. It's quite hot, however, because it is under considerable pressure.
The packs work a little differently than the air conditioner in your house or your car. An air conditioning pack uses what's called an Air Cycle Machine. It's a pretty slick little device that uses ambient air rather than freon for cooling.
Basically, we take the hot bleed air and run it through a heat exchanger with ambient air. This cools it a bit. Then we run it through a compressor, which heats it back up again (but it's still cooler than it was starting out). Then we pipe it through a second heat exchanger. Finally it goes through what's called an expansion turbine which cools the air even more by making it expand. The turbine turns the compressor so the whole unit is self contained. It's almost like a jet engine in reverse. Hot air goes in one end and cold air comes out the other.
In fact, the air coming out is so cold that we actually need to warm it up a bit before we can use it. So we save a little bit of that hot bleed air to mix in with the super cold air.
Cooling the air causes water to condense. This should mostly be trapped in the "coalescer" but sometimes on humid days you'll see mist coming out of the vents. It's just excess moisture. That little vent above your seat? It's called a "gasper". I have no idea why it's called that.
Here's a link to the Wiki article with more information than you ever wanted to know about an Air Cycle Machine:
Here's a diagram of a 727 air conditioner:
Now that we have all this air going into the plane, we have to let it out somewhere. After flowing through the cabin and the cargo compartments it exits out one or more outflow valves. The outflow valves are moved electrically and controlled by the cabin pressure controller. By metering how much air we let out of the plane we can keep the cabin under pressure.
I'm told that back in the days when people smoked on airliners the area behind the outflow valve would be streaked yellow with nicotine. Hope you weren't eating anything right now.
Since pressurization is rather important we need some redundancy. The 757 is pretty typical. We have three sources of bleed air, two engines plus the Auxiliary Power Unit. We have two air conditioning packs. We also have two automatic pressure controllers plus a manual backup. The A300 had two outflow valves. The 757 has only one but it has, if memory serves me, more than one electric motor to operate it.
We also have pressure relief valves. In case something goes drastically wrong these will blow out to keep the cabin from pressurizing too much and popping like a balloon. There are also negative pressure relief valves that blow inwards. We're not a submarine and we're not stressed for negative pressure.
Let's take a look at how this all works. Depending on the aircraft, the automatic pressure controller should pressurize the plane shortly before takeoff and depressurize it shortly after landing. It does this because having a little bit of positive pressure actually strengthens the fuselage.
Why can't we keep the plane pressurized to sea level? To do that we'd need much greater pressure than the 8 psi we normally use. The skin of the plane would have to be much thicker and therefore much heavier.
Once the aircraft starts descending, the automatic controller will start to bring the cabin altitude down to the elevation of the airport we're landing at. It does this at a relatively slow rate to hopefully keep everybody's sinuses and eardrums happy.
Allow me to digress a little bit here and talk about aviation physiology. If you can avoid it, I would suggest not flying with a bad head cold. You'll be OK on the ascent, but on the descent the pressure may not be able to equalize in your sinuses or ear cavity and the results can be excruciating. It feels like someone is trying to drive a hot knife through your face.
Remember when you were a little kid and you tried to pop your eyeballs out by holding your nose and blowing with your mouth closed? You didn't? You must have been a boring kid. Anyway, that's actually the best way to equalize the pressure in your eardrums and sinuses. Much better than chewing gum. Teach your kid to do this and they'll annoy the heck out of you with it but at least they won't be screaming because their ears are hurting them.
So what can go wrong with all this?
Bleed air leak - Hot bleed air leaking from a duct is as hot as a blowtorch and has about the same effect on things it comes in contact with. Once we figure out which system it is (left or right) we'll shut down that whole system by closing the bleed valves. No big deal. One source of bleed air is sufficient to pressurize the jet.
Pack failure - If one of the air conditioning packs starts to run too hot it will "trip off" automatically. We've got another one so not a problem. I have had one of these fail where it filled the plane with the smell of dirty gym socks. Icky but not dangerous.
Pressure controller failure - We've got another one. You see why we like to have at least two of anything important. If both fail we can still regulate the pressure manually but I've never had to do it.
Rapid decompression - This is the bad one. We all saw Goldfinger. This could be caused by both packs failing or by a structural failure of the aircraft (bad).
This is thankfully an extremely rare occurrence. Still, best to keep your seat belt on all the time. I certainly do.
Let's suppose it's not our day. We're cruising along fat, dumb and happy at 40,000 feet when we hear a loud "bang" and a "whoosh", the cabin fills with mist (water vapor) and the oxygen masks drop.
I got to experience this in the Air Force altitude chamber years ago. They don't do that any more because they figured out it's bad for you. Even knowing it was coming - it was an event. In real life you won't know it's coming.
In a rapid depressurization at 40,000 feet you have maybe 20 seconds of useful consciousness before you're off in la-la land. I can't stress this enough, when the flight attendant gives her little speech that everyone ignores and says to put your oxygen mask on before helping your kids - PUT YOUR MASK ON FIRST!
Maybe you didn't hear me. PUT YOUR MASK ON FIRST!!!! We get it. You're a wonderful parent. You love your kids. That's why we need to keep you in the game - so you can help your kids.
The problem we have up front is - we need to get down below 10,000 feet in a big hurry. However, if we think we just blew a big hole in the side of the plane, we have to be gentle with the plane and not make the damage any worse. That means we may not be able to come down as fast as we'd like. It's likely to be rather noisy and probably very cold in the back until we get down and slow down.
OK, that's enough horror theater for one day. This is a very unlikely occurrence and now that you know what to do you're better equipped in case it ever happened.
That's about it. It's a reliable system with plenty of backups, just the way we like it. Other than fiddling with the temperature we usually set it and forget it. And now you can impress your seatmates by knowing that little vent is called a "gasper".