The submarine has a chamber in which water can be filled in or pumped out as required. To make it sink into the water, the chamber is filled with water so that its weight exceeds the up thrust produced on the submarine by the displaced water.
To bring the submarine up, the water in the chamber is pumped out. Now the up thrust produced by the displaced water is greater than or equal to the weight of submarine and hence it can float.