The primary function of the respiratory system is to exchange oxygen and carbon dioxide. Inhaled oxygen enters the lungs and reaches the alveoli. The layers of cells lining the alveoli and the surrounding capillaries are each only one cell thick and are in very close contact with each other. Oxygen passes quickly through this air-blood barrier into the blood in the capillaries. Similarly, carbon dioxide passes from the blood into the alveoli and is then exhaled.
In alveoli, PO2 (Partial pressure of oxygen) = 100 mm Hg
and PCO2 = 40 mm Hg
In alveolar capillaries, PO2 = 40 mm Hg (relatively low because this blood has just returned from circulation & has lost much of its oxygen)
and PCO2 = 45 mm Hg (relatively high because the blood returning from the circulation has picked up carbon dioxide)
Because of the differences in partial pressures of oxygen & carbon dioxide, in the alveolar capillaries, the diffusion of gasses occurs: oxygen diffuses from the alveoli into the blood & carbon dioxide from the blood into the alveoli.
The exchange of gases (O2 & CO2) between the alveoli & the blood occurs by simple diffusion: O2 diffusing from the alveoli into the blood & CO2 from the blood into the alveoli.