Whales are marine mammals and like all mammals they require air to breathe and must come to the surface of the water to take in oxygen.
They are not equipped with gills (which extract oxygen from water) as fish are, instead they need to inhale and exhale oxygen through their blowholes.
All species of whale are broken down into two suborders.
Baleen whales (which have baleen plates and are the larger of the two suborders) have two blowholes while toothed whales (which are smaller and have teeth) have a single blowhole.
The blowhole(s) are located at the top of the whales back (often on or near the head) and act as a passageway to the trachea where air passes through and fills the lungs.
Unlike humans however, whales do not breathe through their mouths because the trachea is not connected to the whales throat.
This separation allows whales to engulf their food while inhaling or exhaling oxygen at the same time when near the surface of the water.
More importantly by having a separate air passage and food passage whales are able to swallow their food underwater without worrying about taking water into their lungs.
When you see water spouting from the whales blowhole it is actually a sign that the whale is exhaling.
In the past people thought that the water coming from the blowhole was water that the whale swallowed or inhaled, however this is not the case because if a whale inhaled the water it would likely enter their lungs and the whale would drown, and since the throat is not connected to the blowhole it is virtually impossible for a whale to spurt out water that it swallowed through its mouth.
The water that spouts from the blowhole is simply water that has collected around the outside of the blowhole.
The whales blowhole is surrounded by muscles to allow the whale to dive without fear of taking in water.
Researchers are unsure of whether or not whales swallow large amounts of water when they engulf their food due to the high concentration of salt in the salt water.
Some species are known to expel the water by pushing it out with their tongue, while keeping their food trapped inside the baleen plates, teeth or mouth, so it quite possible that much of the water whales engulf comes from the water contents of the food they swallow, since much of their food contains water within its body.
Whales likely have specialized livers and urinal systems to help them remove excess salt from the body when they swallow their food and/or water.
In terms of how long a whale can hold its breath it varies depending on the species of whale.
Some species can only hold their breath for a few minutes while other whales can hold their breath for up to 90 minutes or more.
Whales are also considered conscious breathers and never fall completely asleep because they must come up for air or they will die.
Although their brain is partially at rest half of their brain remains alert in order to react quickly to life-threatening situations such as resurfacing for oxygen or running from predators.