Diesel-Electric submarines, however, can stay submerged for far lesser duration because it is powered by its diesel engines while on surface, and by batteries while submerged. Batteries have limited power and hence, run out much sooner (36-48 hours depending upon the submarine type).
Similarly, you may ask, how do submarines get air under water?
First, oxygen must be pumped into the vessel as the crew uses it up by breathing. Oxygen is typically supplied to the submarine from pressurized tanks. A computerized system monitors oxygen in the air and releases fresh oxygen as its needed by the crew.
Where does a submarine get oxygen?
Oxygen is supplied either from pressurized tanks, an oxygen generator (which can form oxygen from the electrolysis of water or by some other means) or some sort of "oxygen canister" (You may remember these canisters because of their problems on the MIR space station -- they release oxygen by a very hot chemical
How does a submarine get its power?
Most large military submarines are now nuclear-powered. Like nuclear power plants, they have small nuclear reactors and, since they need no air to operate, they can generate power to drive the electric motors and propellers whether they are on the surface or deep underwater.