It can be filled with either air or water. When the submarine is on the surface, the ballast tanks are filled with air and the submarine's overall density is less than that of the surrounding water. Ballast tanks are open at the bottom. To dive, the submarine operator opens up valves at the top and lets air out. It's something like blowing bubbles when you are swimming underwater.
Seawater rushes in to fill the space that was taken up by air.
This changes the ship's density. When the density of the submarine is greater than the surrounding water, it begins to sink. This is called negative buoyancy . A moveable set of wings, called hydroplanes, helps control the angle of the dive. To keep the submarine at any specific depth, the crew adjusts the mixture of air and water in separate, smaller ballast tanks.