At its most basic a submarine is any ship that sinks on purpose. Well, that sinks on purpose and has every intention of coming back to the surface, eventually. All ships displace a certain amount of water because of their weight and hull shape. The way that any ship (including a submarine) floats is to ensure that the weight of the water displaced by the ship’s hull is equal to the weight of the ship.
For a surface vessel this is more or less constant ‘ it may fluctuate based on the cargo or fuel load that a ship has, but the displacement of the ship is not going to be adjusted during the day to day operations. On a submarine, this is not the case.
When a submarine submerges it floods special tanks in its hull called ballast tanks. These have the effect of making the hull of the submarine just about heavier than the amount of water the non-flooded compartments of the submarine displaces. The reason it’s not definitely heavier is that a submarine also has tanks called trim tanks to fine-tune its weight with respect to the weight of water around it. The trim tanks are tanks inside the hull of the sub which are kept partially flooded to control the exact balance between the sub’s weight and the weight of water being displaced by the sub.
If the submarine is heavier than the water it displaces it will sink all the way to the bottom, if it is lighter than the water it displaces it will rise again to the surface in general. In practice when operating a submarine is usually just a little bit heavier than the water it is displacing, but it makes up the difference in its buoyancy by moving forward with the dive planes (think of them as rudders for the sub’s up and down movement) providing the little extra fraction of lift the submarine needs to maintain a constant depth.
When the submarine wants to come back to the surface it will expel the water from its ballast tanks. This is done by venting pressurized air into the ballast tanks, which drives the water from the ballast tanks, filling them with air. Once the ballast tanks are full of air again, the sub is no longer in balance it weighs less than the water it is displacing, and so the water pushes it up to the surface until enough of the submarine is out of the water that it is again in balance.
Because the density of water is affected by temperature and the temperature of the water varies with depth, underwater currents, and another less well-understood phenomenon, keeping the submarine in the proper balance between the water it is displacing and its weight is very important. This is the normal job of the trim tanks. As one can tell, keeping the trim tanks properly maintained to keep the submarine submerged is a constant task.
Now, simply keeping the submarine underwater isn’t all that a submarine must do. As mentioned above, the movement of the ship through the water is part of the forces that keeps the submarine at a proper neutral buoyancy. So maintaining power for being able to move is very important. Originally submarines such as the Turtle (used during the Revolutionary War for the first attempted submarine attack on another ship) and the CSS Hunley (A Civil War submarine which actually was the first submarine to sink another ship.) were powered by the muscle power of their crews. Of course, this limited the submarines to very short ranges and slow speeds.
The first modern submarines used a mix of power sources to drive them: diesel engines on the surface and electric motors run off a battery for submerged power. The diesel engines allowed the ship to carry fuel for long cruises, but because diesel engines use so much air to run, they couldn’t be used to provide power underwater, where the only air available was that brought down with the submarine which the crew needed for breathing. The battery, however, had limits of its own: the most significant was it could only store about 18-24 hours worth of power before the sub would have to come back to the surface.
After WWII Captain Hyman Rickover realized that the new power source nuclear power would allow submarines to be built with a power source that wasn’t tied one way or the other to have a ready supply of new air. The advantages of nuclear power for submarines are what have made it possible for submarines to become truly underwater vessels instead of ships that could submerge for short periods of time.
Operations under the Polar ice cap, circumnavigating the globe without surfacing, and similar feats of underwater endurance are all a result of breaking the need for a submarine to surface regularly.