In the vein of Mark
's more or less apt characterization of PhillS
's reasoning (" ...but approaches it backwards... "), I would say his answer needs a slight adjustment of point of view.
Contrary to Alex
's " ...is larger because of the hydrodynamic reasons..., the main thing limiting a submarine's (or any ship's) speed, is the power and duration-capability of its drive. That applies above or below the surface. (Although, an argument could be made that a submerged surface ship...)
When driven by a man-powered screw, submarines were especially non-fast. Diesel engines made them faster, but fuel consumption if going, say, 20 knots would severely limit mission availability versus going perhaps 11-12 knots to one's station and transiting about once there. Fuel consumption rises much faster than speed.
But diesel engines only work underwater when running, using oxygen and fuel, and producing smoke. No one ever found a terrific way to store the smoke onboard or to hide it if exhausted, and while snorkeling both brought air in and got rid of smoke, the smoke was visible in one way or another. Engineers even thought of carrying hydrogen peroxide as a source of oxygen (in a volume as large as the ship's "people tank" would have been), and thereby running the diesels without surfacing and at a depth that would greatly lower the still exhausted smoke's impact on the surface of the water and in the air, but it wasn't a... winner of an idea.
Nuclear power, on the other hand, had none of those difficulties. It introduced its own issues vis-a-vis detectability (pump noise, for example), but while those things were continuous while a set of running diesel generators were intermittant, they are in NO way as detectable as a set of running diesel generators.
And the final nail for diesel-powered submarines as to speed is size. Their power scales up (along with fuel use and it's required storage space, which rises with ship speed exponentially, not multiplicatively), but it is a losing battle.
So the compromise was mediocre speed transiting to and on station and in short chases powered by the diesel engines and a hull shape to amplify that set of conditions.
Actual attack, generally, but not always, involving a submerged approach, was done with the much less detectable electrical-powered engine. Electricity from batteries. And those batteries were both limited in size by the technology of the day AND by their explosion hazard. The latter was a bigger issue 80 years ago than now, but even today, controlling current flow from and to the battery to keep its hydrogen production at safe levels (a multiple variable subject) is of HUGE importance. And batteries are large. Think a hundred cells each four feet tall. To provide a sufficient current to go that (mediocre, "tramp freighter" class) 11-12 knot speed would have been to big to carry, maintain, or vent the hydrogen produced. Not to mention creating the distilled water to keep replacing water being split into gasses.
So the requirement to limit one's attack or fleeing from attack movement to being electrically powered limited their speed underwater versus their (mediocre) speed on the surface.
Now herald nuclear power. Fuel is, in a non-strategic sense, unlimited. One does not have to use electrical power to drive the ship. The steam plant drives it (sorry PhillS
, steam, not electricity, drives the main engine shaft/propeller, not electricity) in all conditions one cares to use it. One may NOT care to use it, more in a second, and it is able to power the shaft at 100% of its capability, surfaced or submerged. So the ship can always go its top speed for either situation, at all times, always. At that point your engineering choices push down a level to things like hull shape and what weapons to use. No mysteries here. Since the ship is vastly harder to even detect, much less fight against, when underwater, one can decide to keep it underwater at all times, and decide accordingly.
Missions also change. The anti-shipping mission was given to aircraft. Hiding nuclear missiles, or sinking Soviet ships, became the missions (though I suppose the Soviets would have said "sinking NATO ships") and the former required, the latter demanded, that submerged sailing dominate one's choices. So the hull and appurtenances were designed to best support that.
Since the power available is the same, a nuclear sub could be designed to travel best on the surface, but even if the modern missions did not need submerged sailing, one would wonder WHY one would want a sub to spend a lot of its life on the surface as there are already ship types that can do anything it is able to do hugely better than a surfaced sub ever could.
So, the reason why they are faster underwater is that since we made nuclear power an option, every design consideration has been made with that mode as the ONLY mode of interest. (With the understood exception of how one is to enter and exit the ship.)
An aside, since the absolutely large interest around the world in diesel submarines has been mentioned, one might point out two things:
There is no nuclear-powered submarine that can be quieter than a modern electrical-powered submarine. Bearing in mind that nukes CAN and do run off their batteries that does not mean they have a weakness here, but for nations that care to spend their money differently, or that refuse to use nuclear power, a modern diesel-powered submarine is absolutely a wonderful thing for coastal/national waters missions. Few of these nations are trying to project power ten thousand miles and for months on end. But they are still slower under water than above it. And so is a nuclear sub when running on its electrical power.
It's still all about the power you can deliver, nothing else. All the rest becomes choices. Nuclear power plants are amazing in an unexpected way: they overwhelm the situation. Usually, folks make dollar-based decisions and so one would never expect something that so overwhelms the most one can even unreasonably require. Different main engine, in whatever ways one would need to change it, and a submarine could go as fast as an aircraft carrier while submerged. And on the surface. Subs have gotten much bigger over the decades, but still never outstripped the power plants available. There is simply no condition in normal, non-damaged operation in which the ship's power plant can't provide flank speed. Well, I never experienced 100% power when running flat out at the max shaft revs allowed. You just don't see that in the engineering world too often. And still quiet enough to position oneself to attack 30+ knot Soviet cruisers racing out of the bottle to open sea (missile sub, in the fantasy that we'd've survived a missile launch when the Soviet backshot would reach us before or right about when the last missile bumped out of its tube, not an attack sub, so we weren't chasing those cruisers down, just placing ourselves and taking shots... if war had happened). Much better positioning than a 3-4 knot electric engine driven diesel sub and all due to our nuclear power plant.