At sea level, atmospheric pressure is 760 mm Hg. As we learned from Dalton’s Law, this pressure is the sum of the partial pressures of all of the gases in the air. The most abundant gas in air is nitrogen, making up about 78% of the air. Oxygen, on the other had makes up about 21% of the air and carbon dioxide about 0.04%. Each of these gases contributes to the total pressure of the air, the pressure that each gas contributes to the total is the partial pressure of that gas. For example, at sea level the total pressure is 760 mm Hg and oxygen makes up 21% of the gas, the partial pressure of oxygen in the atmosphere is 160 mm Hg (760 X 0.21 = 159.6).
The partial pressure for oxygen in the alveoli is 104 mm Hg and its partial pressure in the arterial end of pulmonary capillaries coming from the right side of the heart is 40 mm Hg.
Because of this gradient, oxygen passes from the alveoli into the blood. Blood leaving the pulmonary capillaries has a partial pressure of 104 mm Hg, but some deoxygenated blood of the bronchial veins gets mixed in and by the time the blood leaves the lungs, oxygen's partial pressure has been reduced to ≈ 95 mm Hg. It then travels in pulmonary veins to the left side of the heart where it is pumped to the tissues of the body.
When it reaches the arterial end of capillaries supplying the tissues, it still has a partial pressure of 95 mm Hg. In contrast, the partial pressure for oxygen in the tissue interstitial spaces or extracellular fluid is about 40 mm Hg and maybe even 20 mm Hg in cells, so oxygen follows its gradient and moves out of the blood and into the tissues and cells where it is used in cellular respiration. Deoxygenated blood with an oxygen partial pressure of 40 mmHg travels back to the lungs and the exchange process is repeated all over again.
Carbon dioxide is a byproduct of cellular respiration, so it is released from the cells (46 mm Hg) and has a lower concentration in the tissues (45 mm Hg) compared to arterial ends of tissue capillaries (40 mm Hg). Therefore, carbon dioxide passes from the tissues into tissue capillaries. The cardiovascular system transports it back to the lung capillaries (45 mm Hg) where it can then pass into lower partial pressured alveoli (40 mm Hg) and then be exhaled.
Notice that the gradients for oxygen are much steeper compared to those of carbon dioxide. This is necessary because of oxygen's low water solubility compared to carbon dioxide. In the end, partial pressure and solubility differences balance out and equal amounts of carbon dioxide and oxygen are exchanged.