lung at rest
When the diaphragm contracts, it moves downward, increasing the volume of the thoracic cavity. This leads to a decrease in intraalveolar pressure, causing air to flow in from the atmosphere to equalize the pressure, resulting in inhalation.
If intraalveolar pressure exceeds atmospheric pressure, air will flow out of the lungs due to the pressure gradient. This process is known as exhalation or expiration. It allows the lungs to get rid of carbon dioxide and regulate the levels of gases in the body.