Back in the days when ships were made of wood (or other similar materials), most knew a ship or boat would float since wood floats on water. Sounds simple enough but it gets a bit more complicated when you add weight (or mass) to it. Then you have to think about how to do it to make sure its mass does not sink it. This is where two important principles come into play: buoyancy and the Archimedes principle. The Archimedes principle is that an object in a fluid encounters an upward force equal to that of the weight of the fluid displaced around the object. A ship floats when it displaces a lot of water and that water wants to return to where it was. This creates a force that pushes the ship upwards creating what is called the buoyancy force. A ship that displaces water equal to its own weight will float, while a ship that displaces water greater than its own weight will sink.
Ships and boats then have to be shaped in a way that allows for this displacement to occur so it does not sink. And it allows for a lot of air to be inside as well. Ships are not like solid blocks of steel, which have no air inside. Stability becomes a major issue as well. You want the center of gravity to be stable so it does not tip over easy. In small boats you can see how this works out. A person moving from one side to the other causes the center of gravity to change. Equipment has to be balanced and gear brought aboard has to be kept low and near the center of the boat. That is why it is unwise in small boats to sit on the sides as it will cause tipping. The same principle is true on larger boats and ships. Weight must be distributed so that no one part of the ship is heavier than any other. If the center of gravity on a ship becomes too high due to highly stacked cargo or other things, buoyancy becomes unstable and it will capsize.
Here is a YouTube video that explains how ships float.
1. Buoyancy and how ships float (IMDO Ireland, Marine Institute)
2. Why can boats made of steel float on water when a bar of steel sinks (HowStuffWorks.com)
3. Why can heavy steel ships float? (Science Niblets)
4. Why Do Ships Float Infographic(Bolsover Cruise Club)
5 June 2015-Added 2 new sources (Bolsover and Hyperphysics)