The gases that make up the earth’s atmosphere are subjected to gravity. The atmosphere has a mass of about 5.15×1018 kg. The atmospheric gases at the bottom or those closest to the earth’s surface are compressed by the weight of the air above them. The air closest to the surface is also the warmest, as the air is mostly heated by the land and the sea. When air heats up, its molecules move farther apart, making it less dense. This air then rises to higher altitudes.
The air molecules at lower altitudes are more compressed by gravity than the ones at the higher altitudes. The pressure level is highest right at the surface of the earth because the air at this level is supporting the weight of all the air above it. More weight above means a greater downward gravitational force. As we move up through levels of the atmosphere, the air has less air mass above it and gravity isn’t strong enough to pull down a greater number of particles. So the balancing pressure decreases. This is why atmospheric pressure drops as we rise in altitude.