The process is called osmosis. There is a thin membrane that separates the air in your lungs from the blood in your lungs. The blood has a high concentration of carbon dioxide and a low concentration of oxygen. Any volume of fluid (liquid or gas) wants to equalize, so the carbon dioxide naturally tries to reach the low concentration air while the oxygen tries to reach the low concentration blood. The fun part is your body doesn’t actually know if it has enough oxygen, it only knows how much carbon ioxide it has. So in for example low oxygen, high nitrogen air you can suffocate without noticing since the carbon dioxide is still leaving your body.