Buoyancy is a simple concept. In order to float in water (or any other liquid), an object must displace a mass of the water equal to its own mass. The pressure exerted by the liquid on the hull of the boat (or any other object) at this point is sufficient to counter the downward force of gravity.
The overall density of an object is crucial here, for if the object’s density is greater than that of water (or whatever liquid it is placed in), the object can never displace enough water to equal its mass, and must sink. Boats are generally made of denser-than-water materials however, so you may wonder how it is they do not sink. What is sometimes overlooked is that most of the boat is empty space (filled with air if you want to be picky). On average, the density of the boat is much less than that of water, and so it stays afloat. Should something happen that the ship’s hull would become filled with water, the boat then sinks, for on average, its density is now greater than water’s. Submarines make use of this by filling and emptying tanks with water to manipulate their density. Enough water and they can “dive”, which is really just a controlled sinking. Remove enough water that the density is again less than water’s and the sub again rises to the top.
In order to keep a ship afloat, it is also important that it remain upright. Since the top is generally open to some extent, the boat would quickly fill with water (and sink) if it were to tip over. To remain upright, the boat is constructed so that its mass is concentrated towards the bottom (beneath the center of mass). Ships designed to carry cargo may count on the mass of the cargo in the bottom of the hold to help keep the center of mass low. If the cargo is less than what they wish, the ship may carry ballast – heavy objects that can be stored down low. Ideally this would be something functional. Historically, cannonballs and other lead ammunitions were handy, since they were heavy, took up relatively little cargo space, and could also be used in defense.