A submarine can be made to float or sink in the water.
This is controlled by ballast tanks.
When the tanks are empty, the overall density of the submarine is less, and the weight of the water displaced by the submarine is greater than the weight of the submarine.
Hence it floats on water.
The submarine can be made to sink in water if the water is allowed to enter the tanks such that the overall density of the submarine increases and the weight of the submarine is greater than the weight of water displaced by it. Hence it sinks.