They use a device called an altimeter, which uses air pressure to determine altitude. As you go higher, the air density decreases, causing a drop in air pressure.
SCUBA divers use the same principal to determine how deep they are – as you descend the water pressure increases at a very predictable rate, so measuring water pressure can easily be used to determine depth.
Latest Answers