Because whales breath air, but spend a lot of their time under water, they have developed an efficient system to get enough oxygen. When they breath, they exchange almost the entire air volume in the lungs. Also, whales have the capacity to store much more oxygen in the muscles than land mammals. The nostrils have in whales moved to the top the their head, which makes breathing while swimming a lot easier. This breathing opening is called the blowhole.
Baleen whales have a double blowhole, toothed whales have a single blowhole.
Most whales are excellent divers. When they breath, most of the oxygen is transported from the lungs to the blood and to the muscles. The muscles are rich in a special oxygen-binding protein, called myoglobin. It is related to haemoglobin, the protein that binds oxygen in the red blood cells. When they dive, the blood flow, and hence the oxygen flow, is limited to some vital organs, like the heart and the brain.