Altimeters work via an aneroid barometer to sense the atmospheric pressure. If I climb from 2000ft to 4000ft, the altimeter senses that the pressure has reduced by, let's say, 70hpa, and is calibrated to know that 70hpa = 2000ft.
But the pressure gradient (or rate of change of pressure) reduces with altitude. A climb from FL240 to FL260 might result in a pressure reduction of only 30hpa. Yet it still knows that the aircraft climbed 2000ft. How does the altimeter do this?