Some of the best moments in World War II movies occur when, during a battle at sea, a periscope pokes up from the water, surveying the ocean terrain. Cut to a submarine gliding through the depths. Torpedoes away, and the enemy battleship is doomed. How do these amazing vessels rise and sink so quickly to specific depths?
Although submarines are sophisticated machines, their ability to rise and sink is based on the elementary principle of buoyant force. Say you fill your bathtub with water and put a rubber gym ball on the surface of the water. It floats because the air-filled ball is less dense than the surrounding water. But poke a hole in the ball and as water displaces the air, the overall density increases until the ball is heavy enough to sink to the bottom.
A submarine works in much the same way, with one major exception: a sub can alter its buoyancy by manipulating overall density. Submarines come equipped with tanks that can be filled with various levels of water and air. When a sub floats on the surface, its tanks are filled mostly with air, which makes the sub less dense than the surrounding water. When the crew wants to make the sub sink, they open valves to allow just enough water to flood the tanks and make the sub sink to a specific depth.
Of course the sub must be able to rise again after filling its tanks with water. To that end, submarines carry tanks of compressed air that can be used to displace water from the tanks and increase buoyancy.