Modern aircraft are all equipped with a device called an altimeter that displays the height at which an aircraft is flying. It does this by comparing the air pressure outside the aircraft to the air pressure it would expect at the ground. It is a component of what's called the Pitot-Static System of an aircraft and is connected to the static pressure port. It's nothing more than a simple mechanical device!
Generally, there are two types of altimeters: sensitive and non-sensitive. The difference is that a sensitive altimeter that can be adjusted for the current pressure. A small group of numbers, displayed in what is referred to as a 'Kollsman window', show the selected barometric pressure in inches of mercury or millibars depending on the calibration. A pilot will adjust his altimeter to match the local setting given by Air Traffic Control.
Now, believe it or not, there are multiple types of altitude. The two most common are height above Mean Sea Level (denoted by MSL) or height Above Ground Level (denoted by AGL). As mentioned earlier, the altimeter compares the current outside air pressure to what it would expect on the ground. Because the ground height varies significantly from place to place, the altimeter shows altitude in MSL. When an accurate pressure reading is set into the Kollsman window on the ground, the altimeter will always show the current ground elevation!