The movement of gases into and out of the lungs is determined by the difference in pressure between the atmosphere and the chest, or the thoracic cavity. Pressure in the thoracic cavity is regulated by the diaphragm, which in turn is assisted by the movement of the intercostal muscles.
During inspiration (inhalation), the diaphragm flattens and pulls downward, the external intercostal muscles, contract, the rib cage pulls up and outward, chest volume increases, pressure in the lungs decreases and air moves into the lungs.
During expiration, (exhalation, the diaphragm is relaxed and becomes dome shaped, the internal intercostal muscles contract and the external intercostal muscles relax, the rib cage falls, chest volume decreases, pressure in the lungs increases and air moves out of the lungs.