Breathing consists of two phases called inhalation and exhalation.
Inhalation
In order for air to be drawn into the lungs during inhalation the volume of the thorax must increase. This is brought about due to the contraction of respiratory muscles. The diaphragm contracts and flattens and the intercostal muscles contract to pull the ribs up and out. The increased volume within the thoracic cavity lowers the pressure within the lungs with respect to the atmospheric pressure. Consequently, air is drawn into the lungs down a pressure gradient.
Exhalation
Inhalation is now complete and the next step is exhalation. The diaphragm relaxes and moves up and the relaxation of the intercostal muscles moves the ribs in and down. This has the effect of decreasing the volume within the thoracic cavity and increasing the pressure within the lungs with respect to atmospheric pressure. As a result, air moves out of the lungs down a pressure gradient.