Submarines do not run out of air in the same way that a person might run out of air while scuba diving, as they carry a supply of compressed air for their crew to breathe while submerged. Modern submarines are equipped with advanced life support systems that ensure a constant supply of breathable air for the crew.
The air supply on a submarine is stored in high-pressure air tanks. These tanks are filled with compressed air before the submarine dives, and the air is gradually released into the submarine's living spaces to maintain a breathable atmosphere for the crew during their underwater operations. As the submarine consumes oxygen and produces carbon dioxide through the crew's breathing, the carbon dioxide is removed from the air, and fresh oxygen is supplied to keep the air safe and breathable.
Submarines are also equipped with systems to remove excess humidity and carbon dioxide from the air, ensuring that the environment inside the submarine remains comfortable and healthy for the crew during extended periods underwater.
However, submarines do have limits to the amount of time they can remain submerged due to factors such as the amount of onboard food, fuel, and other supplies necessary for the crew's well-being and the operation of the submarine. When these resources start to deplete, the submarine will need to resurface for resupply and to exchange air. The duration a submarine can stay submerged without resurfacing depends on its class, design, and the specific mission it is undertaking. Some modern submarines can remain submerged for weeks or even months at a time, but eventually, they will need to return to the surface for replenishment and crew relief.