The function of the respiratory system is to deliver air to the lungs. Oxygen in the air diffuses out of the lungs and into the blood, while carbon dioxide diffuses in the opposite direction, out of the blood and into the lungs. External respiration is the process of gas exchange between the atmosphere and the body tissues, and includes ventilation (inhaling and exhaling air) and gas transport (the process of distributing the oxygen throughout the body and collecting CO2 and returning it to the lungs). Internal respiration occurs inside the cell, using oxygen and glucose to generate energy (ATP), and producing waste CO2.