Gas exchange in the lungs happens in millions of tiny air sacs called alveoli. Oxygen diffuses from the air in the alveoli into the blood in the surrounding capillaries. Carbon dioxide diffuses the other way, from the blood into the alveoli, to be breathed out. Diffusion is the net movement of particles from a region of higher concentration to a region of lower concentration, down a concentration gradient.
The alveoli are adapted for fast diffusion. There are millions of them, so the total surface area is very large. Each alveolar wall is one cell thick, and the capillary wall is also very thin, so the diffusion distance is short. Each alveolus is covered by a dense network of capillaries. Blood flow carries oxygen away and brings more carbon dioxide, and breathing brings in fresh air and removes air rich in carbon dioxide. Both keep the concentration gradient steep.
Three factors affect the rate of diffusion. A larger surface area gives a faster rate. A steeper concentration gradient gives a faster rate. A shorter diffusion distance, which means a thinner membrane, gives a faster rate. Fick's law combines them: the rate of diffusion is proportional to the surface area multiplied by the concentration difference, divided by the thickness of the membrane. So if the surface area doubles, the rate is doubled. If the thickness doubles, the rate is halved.