According to Archimedes' principle, a ship will float when the weight of the water it displaces equals the weight of the ship and anything will float if it is shaped to displace its own weight of water before it reaches the point where it will submerge. This is kind of a technical way of looking at it. A ship that is launched sinks into the sea until the weight of the water it displaces is equal to its own weight. As the ship is loaded, it sinks deeper, displacing more water, and so the magnitude of the buoyant force continuously matches the weight of the ship and its cargo.
A ship is made hollow so that its average density is lower than that of water. This way it displaces water equal to its own weight without reaching a point where it will submerge.