Manoeuvring Room
Underwater there is no air for an engine. A battery boat lives on what it stored and has to come up to breathe; a nuclear boat makes its own power for as long as the food lasts. Run a three-day patrol both ways.
The battery model is a toy calibrated on a Second World War fleet boat: about 48 hours at 2 knots, an hour or two at full speed. Recharging takes about six hours at snorkel depth.
Two engines in one boat
From John Holland's boat of 1900 onwards most submarines carried two kinds of power: an engine for the surface, and electric motors with a big battery for underwater. On the surface or at snorkel depth the diesels run, turning generators that drive the boat and charge the battery. Dived, everything runs on the battery.
WWII diesel-electric boats could stay submerged for roughly one to two days at a crawl before the battery ran flat: a US Gato class about 48 hours at 2 kn, a German Type VIIC about 80 nmi at 4 kn. At full submerged speed the battery lasted only about an hour or two. The Type XXI could go about 340 nmi at 5 kn.
Speed is expensive
Pushing a hull through water takes power that rises roughly with the cube of speed: going twice as fast takes about eight times the power. A battery that would last two days at a walking pace is empty in an hour or two at full speed. So diesel boats creep, and sprint only when they must.
The reactor
A nuclear reactor needs no air. It heats water, which makes steam, which turns turbines for the shafts and the electrics. USS Nautilus, the first, went to sea on nuclear power in January 1955; in 1958 she crossed under the North Pole.
With a reactor, the limits become the crew and the food. A nuclear boat can stay down for months and run fast the whole time. The price is size, cost, and a reactor plant that is never truly silent.
Without air, without a reactor
Engines that do not need outside air are older than they sound: in the 1860s Narcís Monturiol's Ictíneo II in Barcelona ran a steam engine heated by a chemical reaction that also released oxygen. Modern non-nuclear boats can carry similar "air-independent" plants, such as fuel cells, that stretch a dive from days to weeks at slow speed.