Stability is one of the most important factors to consider when designing a ship, but it’s often overlooked in popular references. Staying upright is an important function of any ship, and insufficient stability resulted in the loss of Vasa and HMS Captain, as well as three destroyers during Typhoon Cobra. One key means of avoiding this fate in bad weather is to keep the ship's center of gravity low, which often restricts design and particularly modification, a notable case being the installation of light AA batteries during WWII.
There are three important points in defining a ship’s stability. The first, two, the centers of gravity (CG) and buoyancy (CB), are the points through which all of the forces of a given type can be assumed to act. Naively, we’d expect the ship to be stable if the CG is below the CB, so any roll would produce a righting arm. While a ship with such characteristics would be stable, the vast majority of ships achieve stability through a different mechanism.1 Instead, ships take advantage of the fact that their form near the waterline causes the CB to move to the side that is more deeply submerged, creating what is known as a righting arm (GZ) and pushing that side back up. In normal operations we can assume that the CB is essentially ‘hanging’ from a point, called the Metacenter (MC), making it easy to find how much the CB has moved at a given angle of heel.
This property makes it easy to analyze stability. The most important metric is how high above the CG the MC is, known as metacentric height (GM). Righting arm can be approximated as GM*sin(roll angle), so that stability is directly proportional to GM. If the CG and MC were in the same place, GM is zero and there’s no restoring force if the ship rolls. If the metacentric height is negative, then the ship will loll, falling to one side until the CB moves enough to give a positive righting arm. This is very dangerous, and can quickly lead to the ship capsizing. Obviously, modifications which place weight high in the ship reduce GM by moving the CG upward.
So we just want a large metacentric height, right? Not so fast. There are a couple of limitations to this analysis. First, metacentric height is only an approximation, and it begins to break down as heel passes 10 degrees or so. Particularly when the edge of the deck enters the water, the CB stops ‘hanging’ beneath the metacenter, and has to be calculated directly to get the value of the GZ. The maximum righting force almost always occurs at this point. HMS Captain, for instance, had a reasonable GM value at shallow angles of roll, but her freeboard was so low that the deck edge submerged quickly, and her maximum GZ was thus too low.
Another problem with a large GM is that GM is a measure of how quickly a vessel recovers from a roll, and a large GM makes the ship tend to snap back, producing an uncomfortable ride. A ship with a low GM rolls more slowly and is generally more comfortable. For comfort, ocean liners were built with quite low GMs and used a high freeboard to ensure safety. A fast roll is also bad for gunnery, and in some cases, most notably the British Revenge class, ships were built with low GMs to make them better gun platforms.
Third, the ship tipping over is not the only possible way for excessive heel/roll to sink a ship. Another important consideration is the downflooding angle, the point at which water can start to enter the ship through hatches, ventilators, or the like. Lack of attention to downflooding angle can doom a ship with apparently adequate stability.
Of course, warships also care about damaged stability.2 Flooding is bad for stability, not just due to the loss of buoyancy/movement of the CG, but due to what is known as the Free Surface Effect. Free surface occurs in partially-flooded compartments, as the liquid inside flows to lower side of the compartment, shifting the CG of the liquid outboard of the CG of the compartment. This can also happen with liquid cargo, such as oil, and even with grain and other bulk cargoes. It's a much bigger problem on ships with wide areas for the fluid to work in, such as Roll-on Roll-off (Ro-Ro) ferries. The MS Herald of Free Enterprise was lost primarily to the free surface effect.
Damage can also change the effective hull shape. This was a concern with the internal belt on the Iowas, and was a major driver of light belts on Russian ships after the Russo-Japanese war. Damage from light shells tearing up the sides of the ship above the belt reduced their range of stability from 30 degrees to 15 degrees, and postwar ships had light belts above the main one to preserve their stability after action.
All of this discussion has been about rolling, and technically GM is the transverse metacentric height. Similar values can be calculated longitudinally, defining the ship's motion and stability in pitch. In practice, these are much less important.
None of this discussion should lead you to believe that stability is the only factor in roll. While the roll period is set by the metacentric height and radius of gyration, the magnitude of roll is heavily influenced by the underwater hull form. For reasons beyond the scope of this post, some ships roll much more than others. The Royal Sovereign class were initially known as the "Rolling Ressies" because of the large angles they reached, but they were later refitted with bilge keels, which essentially damped the roll.3 Another interesting case is that of the German Nassau class. Their roll period happened to coincide with the average period of waves in the North Sea, and they rolled dangerously when they first entered service. Bilge keels were added, and the problem mostly went away.
Metacentric height is measured in practice by a procedure known as inclining. The ship is carefully prepared4 and then weights are moved across the deck to give a known heeling moment. The ship's heel is measured. A few data points gathered in this way can be used to calculate GM.
More information on stability and damage can be found in the 1945 USN Damage Control Manual
1 Except submarines, which, for obvious reasons, can’t take advantage of the method surface ships use. ⇑
2 Merchant ships theoretically do, but in practice they're a lot less careful about it. ⇑
3 Bilge keels impose a small performance penalty, so they often are added after the ships are completed and found to need them. ⇑
4 The British checklist began with "Make sure the ship is afloat and not resting on the bottom" and included paying very careful attention to all tanks so that free surface didn't mess up the results. ⇑