Submarines are based on Archimedes’ Principle. A submarine can dive into the water or rise to the surface as needed.
The compartments of a submarine that help in its floatation are the ballast tank and the compressed air tank. To sink, the ballast tanks are filled with water so that the average density of the submarine becomes greater than the density of sea water, and the submarine sinks. To rise, the water from the ballast tanks is forced out into the sea by allowing air from the compressed air tank to enter the ballast tank. As a result, the average density of the submarine decreases, and the submarine rises.