The diaphragm contracts during inspiration, increasing thoracic cavity volume and reducing pressure to draw air into the lungs. It relaxes during expiration, reducing volume and increasing pressure to expel air from the lungs.