Each branch of the bronchial tree eventually sub-divides to form very narrow terminal bronchioles, which terminate in the alveoli. There are many millions of alveloi in each lung, and these are the areas responsible for gaseous exchange, presenting a massive surface area for exchange to occur over.
Each alveolus is very closely associated with a network of capillaries containing deoxygenated blood from the pulmonary artery. The capillary and alveolar walls are very thin, allowing rapid exchange of gases by passive diffusion along concentration gradients.
CO2 moves into the alveolus as the concentration is much lower in the alveolus than in the blood, and O2 moves out of the alveolus as the continuous flow of blood through the capillaries prevents saturation of the blood with O2 and allows maximal transfer across the membrane.