Every aircraft has a small hole in its side called the static port. It does one job: it lets the instruments feel the pressure of the still air around the aircraft. Everything the altimeter shows you comes from that one number.
Air has weight. At sea level, the column of air above each square centimetre weighs a little over a kilogram, and that weight is the pressure you feel: about 1013 hPa on a standard day. Climb, and there is less air above you, so less weight, so less pressure.
Notice the curve is not a straight line. Air is squashable, so the lower layers are compressed by everything on top of them. That is why the first 18,000 ft take away half the atmosphere, and why near the ground pressure drops by roughly 1 hPa for every 27 ft. Remember that number. It comes back later.
A box that breathes
To turn pressure into a needle movement, the altimeter uses an aneroid capsule: a sealed, flexible metal box with the air taken out. Outside air presses on its corrugated walls. When the pressure falls, the capsule relaxes outward by a fraction of a millimetre.
The instrument maker calibrates the dial with the ISA, the standard atmosphere you see in figure 1. So when the needle says 6,000 ft, what it really means is: “the pressure here is what the ISA has at 6,000 ft.” On a day that is not standard, those are not the same thing.
Telling it where zero is
Sea-level pressure changes from day to day, and from place to place, by tens of hectopascals. A difference of 10 hPa is 270 ft of altitude, plenty to matter on an approach. So the altimeter has a knob, and a small window called the subscale, where you set the pressure it should treat as zero.
Try setting the subscale one hectopascal at a time and watch the needle. Higher setting, higher reading. That is the whole trick behind every altimeter question: work out which way the setting moved, then multiply by 27.
High to low, look out below
Now the dangerous part. Say you set QNH before departure and forget about it. As you fly towards an area of lower pressure, the altimeter has no idea the weather changed. It just keeps you at the height where the pressure is what it expects.
The aircraft never felt a descent. The altimeter never moved. And yet it is now hundreds of feet lower than the pilot believes. This is why controllers pass you the local QNH, and why the rhyme is drilled into every student: high to low, look out below. The same thing happens flying from warm air into cold, because cold air is denser and its pressure surfaces sit lower.