Altitude affects air pressure due to gravity. Gravity causes the pressure to increase or decrease based on the air's distance from sea level. Pressure decreases at higher altitudes.
At higher altitudes, molecules in the air are less affected by gravity. This causes them to have less weight, facilitating their expansion. Molecules closer to the Earth's surface are pulled closer together due to gravity, which causes an increase in air pressure.
Molecules at lower altitudes are compressed under those from higher altitudes, also leading to greater air pressure. Temperatures at high altitudes are lower than those at sea level due to the expansion and distance of air molecules from each other.