If you put a nail or a lump of iron in water it sinks at once. A piece of wood of the same size floats. Take a sheet-iron put that on the water. It floats. It weighs just as much as the lump of iron that sinks, but the weight is spread or distributed over a larger volume of water . It has been made lighter than the total amount of water it rests upon.An object sinks only when it displaces equal amount of water.The combined density of air and steel is less than that of sea water that is why the ship floats.
A ship is just such a hollow vessel. When there is nothing in it, a ship stands high, almost on the surface of the water. As it is loaded with goods and people, it rides deeper.
All ships have a water-line painted plainly around the hull. This is the safety loading line. No ship owners are allowed to load a vessel so heavily that that water line sinks below the surface of the water. Air spaces must be left, to keep the ship and its cargo lighter than the water that is beneath them.