Submarines need large amounts of electricity to operate safely under water. They charge their batteries using diesel or nuclear-driven generators. Diesel subs must surface to recycle their batteries because carbon monoxide fumes are deadly. Nuclear ones can remain under water for months and even years.

If its generator fails, a submerged nuclear submarine relies on its batteries to surface. Under these circumstances, the batteries are their crew’s only hope. The rooms they are in are among the biggest spaces on the vessel. They need many battery cells in series in a large compartment. This is usually in the lower section of the hull to keep the vessel stable.
Why Lead-Acid Batteries are the Obvious Choice
Although not new technology like a modern submarine is, lead-acid batteries are the preferred choice because they are relatively inexpensive, and reliable. They present less threat of fire or explosion than the main alternative, lithium-ion. They are, however, heavy. On a submarine, weight is a critical factor, although perhaps not the way you think.
How Heavier Batteries Make Good Sense for Submarines
Surface vessels must stay afloat, while submarines need to be able to slip below the surface. Air fills every cubic foot of space. Each cube needs sixty pounds of weight to counter-balance it. A relatively small amount of seawater in the flotation tanks overcomes this equilibrium, and allows the vessel to submerge below the surface.

The weight of lead-acid batteries thus becomes irrelevant in submarines, because they form part of the counter-balancing ballast. This overcomes the weight / bulk disadvantage where after reliability wins.
Although technically similar to the starter-batteries in autos, modern submarine battery rooms are complex installations. They have to be. Batteries are at the heart of submarines in several ways. They keep the vessel alive, purify the air, power the motors, turn the propellers, and empty the flotation tanks so it can surface.
Related
Important Points You have to Know about Marine Battery
The Difference Between Galvanic Cells and Electrolytic Cells