This is achieved by a rather clever device where air will move from an area of high pressure to one of low pressure. Just as the air in a balloon rushes out, so the air from the atmosphere rushes into the lungs. This is how the process works. The intercostal muscles between the ribs contract and the rib cage moves up and out. This makes the air pressure inside the thorax lower than the surrounding air pressure, so air rushes into the lungs.
Gas exchange happens in the alveoli.
These two sections are usually tested in the Higher papers. During heavy exercise the muscle cells respire so rapidly that the bloodstream cannot provide enough oxygen. The muscles also become fatigued and aerobic respiration slows down. The muscles then start to produce Lactic acid from the incomplete breakdown of glucose instead of carbon dioxide and water. The process is not an efficient way to produce energy, but it means that the muscles can still work in the absence of oxygen.