Remember that an air parcel is a bubble of air enclosed within an imaginary, elastic boundary keeping it separated from the rest of the air. No gas is allowed to leave or enter the parcel, but the shape of the parcel is allowed to change. As an air parcel moves around in the atmosphere, its shape changes in response to changes in air pressure surrounding the parcel. What happens is that the size of the air parcel will change so that the air pressure inside the air parcel becomes the same as the air pressure surrounding the air parcel. Why? If the air pressure surrounding the parcel is different than the air pressure inside the parcel, then the pressure forces on the parcel surface are not balanced, and the parcel is forced to change its shape (volume).
So when an air parcel rises upward in the atmosphere, it must expand because the air pressure surrounding the parcel gets lower (See Figure H.) This means that the number density of air in the parcel decreases (same number of gas molecules but in a larger or expanded volume). The air in the parcel uses energy to expand (increase its size), so the temperature of the parcel also decreases. Mathematically, the pressure, number density, and temperature of a gas are related in an equation called the gas law:
Pressure decreases when a parcel is lifted. From the gas law, the (density x temperature) must also decrease. Both number density and temperature decrease when a parcel expands. By the way, you may remember the gas law equation from chemistry class, where it is typically expressed in the form PV=nRT. This expression above is the same equation except number density is used instead of volume and number of moles of gas. An air parcel must expend energy in order to expand. This expenditure of energy also acts to decrease the parcel temperature as it rises and expands.
Conversely, when an air parcel is lowered in the atmosphere, it is compressed because the air pressure outside the parcel increases. When parcels are lowered the air pressure, number density, and temperature of the gas in the parcel increase. In this case the surrounding atmosphere is supplying energy to compress the parcel (decrease its size). This transfer of energy from surrounding environment to the parcel also acts to increase the parcel temperature.
A couple of everyday examples may help you to keep this straight. When air under high pressure, like that contained in an aerosol spray can or a bicycle tire, is released it feels cold. The spray nozzle or tire valve gets cold because the air that is coming out is expanding and cooling. When air is compressed, like when operating a bicycle pump, it feels warm. The pump cylinder gets warm because air is getting compressed into the bottom of the cylinder, which heats it up.