Answer:
The majority if a submarine is not the space where the crew lives, but large tanks called ballast tanks. When the submarine wants to sink, water is pumped into the ballasts and the submarines average density gets higher than that of the surrounding water so it sinks. When this happens the air is compressed into smaller tanks, but when the submarine wants to rise the air is pumped back into the ballasts, forcing the water out, dropping the average density llower than the water so it floats.
When it wants to remain neutral, halfway between the surface and the bottom, the amount of air and water in the ballasts is regulated until it is equal, so the submarine doesn't move.
Hope this helps!