This is how modern submarines do not run out of oxygen while submerged
The United States Navy is the biggest, most technologically advanced Navy in the world. Sometimes it is easy to forget the humble beginnings from which our prestigious military came from. The sea is a cruel mistress that hides her power beneath the waves. The secrets of the abyss have long intrigued sailors and civilians alike. Thanks to the foundation provided by the first pioneers we now have submarines capable of defending freedom at a moment's notice from any corner of the earth. As breathtaking as the human achievement is to sail under the sea, it begs the question: How do sailors not run out of oxygen? When did humans start experimenting to solve that challenge? This is how modern systems regulate oxygen and other essential chemicals within the hulls of the most powerful Navy on earth.
The Turtle is the most successful failure of the Revolutionary War. It was designed by David Bushnell in 1775 as the first one-man submersible to be used in the battle for our nation's right to exist. While it was not a success in combat it was a successful proof of concept that the military would perfect to its most lethal potential centuries later. The Turtle was used against the HMS Eagle but was combat ineffective against metal hulls. One way that Bushnell designed The Turtle to use less oxygen is due to the use of bio-luminescent fungus. Oxygen candles had not been invented yet and so the military needed to improvise a way to reduce or eliminate the use of conventional candles which would burn out the breathable air for the operator. However, the military needed another more efficient and cost effective way to maximize the time a crew could remain under water.
When underway, submarines will need to replenish their oxygen using Oxygen Candles. Every compartment is carefully monitored using a Central Atmospheric Monitoring System. This helps the crew identify any problems, such as gas leaks, and deal with the problem immediately. The Navy utilizes special machines called 'sniffers' to pinpoint a gas leak. The crew will use some variant of Electrolysis to purify air in combination with the CAMS. If the sub loses power and it cannot produce oxygen the primary way, the crew will light an oxygen candle.
Producing oxygen through a process of electrolysis is easily achievable on a submarine with a nuclear reactor. The process takes a lot of energy to produce the desired life-saving gas. However, one thing the video above glossed over was that if you use this process on straight up salt water you will create chlorine gas and hydrogen, no oxygen. The stakes are a bit higher than "not environmentally friendly." We would straight up die. So, the Navy has developed systems that will purify the water first using either distillation or reverse osmosis. Then the process of electrolysis would be safe to use.