The main function of the respiratory system is gaseous exchange. This refers to the process of Oxygen and Carbon Dioxide moving between the lungs and blood. Diffusion occurs when molecules move from an area of high concentration (of that molecule) to an area of low concentration. This occurs during gaseous exchange as the blood in the capillaries surrounding the alveoli has a lower oxygen concentration of Oxygen than the air in the alveoli which has just been inhaled.
Both alveoli and capillaries have walls which are only one cell thick and allow gases to diffuse across them.
The same happens with Carbon Dioxide (CO2). The blood in the surrounding capillaries has a higher concentration of CO2 than the inspired air due to it being a waste product of energy production. Therefore CO2 diffuses the other way, from the capillaries, into the alveoli where it can then be exhaled.
To demonstrate the use of Oxygen and Carbon Dioxide in respiration you can look at the amounts of both gases which we inhale and then exhale. The air we breathe contains approximately 21% Oxygen and 0.04% Carbon Dioxide. When we exhale there is approximately 17% Oxygen and 3% Carbon Dioxide. This shows a decrease in Oxygen levels (as it is used in producing energy) and an increase in Carbon Dioxide due to it being a waste product of energy production.