The action of breathing in and out is due to changes of pressure within the thorax, in comparison with the outside. This action is also known as external respiration. When we inhale the intercostal muscles (between the ribs) and diaphragm contract to expand the chest cavity. The diaphragm flattens and moves downwards and the intercostal muscles move the rib cage upwards and out.
This increase in size decreases the internal air pressure and so air from the outside (at a now higher pressure that inside the thorax) rushes into the lungs to equalise the pressures.
When we exhale the diaphragm and intercostal muscles relax and return to their resting positions. This reduces the size of the thoracic cavity, thereby increasing the pressure and forcing air out of the lungs.
The rate at which we inhale and exhale is controlled by the respiratory centre, within the Medulla Oblongata in the brain. Inspiration occurs due to increased firing of inspiratory nerves and so the increased recruitment of motor units within the intercostals and diaphragm. Exhalation occurs due to a sudden stop in impulses along the inspiratory nerves.
Our lungs are prevented from excess inspiration due to stretch receptors within the bronchi and bronchioles which send impulses to the Medulla Oblongata when stimulated.
Breathing rate is all controlled by chemoreceptors within the main arteries which monitor the levels of Oxygen and Carbon Dioxide within the blood. If oxygen saturation falls, ventilation accelerates to increase the volume of Oxygen inspired.
If levels of Carbon Dioxide increase a substance known as carbonic acid is released into the blood which causes Hydrogen ions (H+) to be formed. An increased concentration of H+ in the blood stimulates increased ventilation rates. This also occurs when lactic acid is released into the blood following high intensity exercise.