In order to draw air into the lungs the diaphragm or muscle extending across the bottom of ribcage contracts and the thoracic cavity expands with the help of the intercostals muscles or muscles between ribs. As a result, the lungs are inflated with air. Then the diaphragm relaxes and elastic recoil causes the thoracic cavity to contract.