As air is heated it expands becoming less dense, and as a result, lighter. Because it is lighter, it rises upwards above the cooler air. As it does so, this air continues to expand. This is because there is less pressure higher in the atmosphere, allowing the air molecules to spread out more.
In order to spread out, these molecules require energy. As they do so, they become less agitated and vibrate slower. As a result, the temperature of these air molecules drops, despite the fact that no heat has been removed from them. This process is referred to as adiabatic cooling.
As the air cools down, it again begins to fall towards the surface of the Earth. As it sinks deeper into the atmosphere, the pressure from the weight of the air above it pushes air molecules closer together, causing them to become more agitated and heating them up again. As a result, their temperature rises, even though no heat has been added. This process is referred to as adiabatic warming.