When we inhale, the diaphragm contracts and moves downward, while the rib muscles lift the ribs up and out. This increases the volume of the chest cavity, causing air to rush into the lungs. When we exhale, the diaphragm relaxes and moves upward, while the rib muscles relax, reducing the chest cavity's volume and pushing air out of the lungs.