Every time you breathe in, oxygen from the air you inhale passes through the thin walls of the alveoli into the surrounding capillaries, where red blood cells pick it up using a protein called hemoglobin .From there, it travels through the pulmonary artery to the lungs, where it flows from the capillaries back into the alveoli in exchange for the incoming oxygen.When you breathe out, or exhale, your diaphragm and rib muscles relax, reducing the space in the chest cavity.At the same time, carbon dioxide, the waste gas carried back to the lungs from the cells of the body, trades places with the oxygen, moving from the blood in the capillaries back into the alveoli.The carbon dioxide, once in the bloodstream, travels back to the heart, where it enters the right side.From the alveoli, the carbon dioxide is breathed back out.As the chest cavity gets smaller, your lungs deflate, similar to how air releases from a balloon.At the same time, carbon dioxide-rich air flows out of your lungs through the windpipe and then out of your nose or mouth.