Why don't ships capsize if their centre of gravity is above their centre of buoyancy? So our teacher recently showed us this diagram of the forces acting on a ship:

However, if you tilted the ship a little so that the centre of gravity were slightly offset, surely there would be an runaway effect where the entire ship would tilt further until it capsized? (A bit like standing a pencil on its tip and it falling over I guess).
Obviously this doesn't happen in real life; ships return to the vertical if tilted, but how could this be the case if their centre of buoyancy is above their centre of gravity?
 A: G does not need to be below B. 
Although the position of G is fixed in the ship (provided cargo etc is fixed in place), the position of B changes as the ship tilts and the profile below the waterline changes. Provided that B moves further out than G, there will be a restoring moment tending to right the ship. 
To be stable, G should be below M, the Metacentre, which is a position on the centreline about which B appears to rotate as the ship tilts. The distance GM, the Metacentric Height determines the period of tilting oscillations. If GM is large (as it usually will be if G is below B), the oscillation period is small, and acceleration is high - which is uncomfortable for passengers/crew and potentially damaging to cargo and the ship.
A: The problem is solved by keeping the center of mass(CM)very low compared to the center of byouyancy(C.B). Then notice that the couple which will act after tilting the ship will stabilise it. That is precisely why all ships store most of their goods in the cargo holds below deck. A ship with a lot of cargo on the deck is in danger of capsizing. However, even that is sometimes averted by making the ships way flat, and securing the cargo on deck. As such this stabilises the ship(you will see this type in many aircraft carriers, and also on large cargo carriers.)
