There are many things on a submarine that have to work just right. The sub has to submerge and travel underwater. It has to maintain a particular depth under the water, and it has to be able to resurface. Communications equipment and other types of equipment need to operate properly. There needs to be enough food, water, and air for the crew. The interior of the sub must be maintained at a comfortable temperature. And everything must be done in a small, enclosed space deep under the ocean.
How does a submarine submerge, or sink down under the water? To submerge, it must become heavier than the water under it. A sub is already heavy. Usually, its sides are made of steel. But with the air inside, it still floats. So, to become even heavier, a sub must replace some of its air with water. A submarine has large compartments called ballast tanks that can be filled with either water or air. When it is time to submerge, the ballast tanks are filled with water. As soon as the sub becomes heavy enough, it starts to sink.
When it gets to the right depth, a sub needs to stay at that depth in order to travel. To do that, the amount of water and air in the ballast tanks are constantly adjusted.