During inhalation, the diaphragm contracts and moves downwards, which increases the space in the chest cavity into which the lungs expand. The intercostal muscles between the ribs also help in enlarging the chest cavity. This movement decreases the pressure inside the chest cavity, allowing air to rush in and fill the lungs. On the other hand, during exhalation, the diaphragm relaxes and moves upwards into the chest cavity, while the intercostal muscles relax to reduce the space in the chest cavity. This movement increases the pressure inside the chest cavity, causing air to be pushed out of the lungs.