This displacement of water creates an upward force called the buoyant force and acts opposite to gravity, which would pull the ship down. Unlike a ship, a submarine can control its buoyancy, thus allowing it to sink and surface at will.
To control its buoyancy, the submarine has ballast tanks and auxiliary, or trim tanks, that can be alternately filled with water or air (see animation beside). When the submarine is on the surface, the ballast tanks are filled with air and the submarine's overall density is less than that of the surrounding water. As the submarine dives, the ballast tanks are flooded with water and the air in the ballast tanks is vented from the submarine until its overall density is greater than the surrounding water and the submarine begins to sink (negative buoyancy).
A supply of compressed air is maintained aboard the submarine in air flasks for life support and for use with the ballast tanks. In addition, the submarine has movable sets of short "wings" called hydroplanes on the stern (back) that help to control the angle of the dive. The hydroplanes are angled so that water moves over the stern, which forces the stern upward; therefore, the submarine is angled downward.
from http://science.howstuffworks.com/transport/engines-equipment/submarine1.htm
and http://www.dynamicscience.com.au/tester/solutions/war/subquestionforces.htm