When riding a bike, your body should be situated as follows:
When the pedals are in their lowest positions, your legs should be almost completely extended.
Notice the bold text? That's because it's important. It allows for efficient pedaling (why waste energy?) and protects your knees from undue strain.
"So, keeping that in mind, what frame size would be right for me?"
A 16" frame is most suitable for riders ranging from 5' to 5'8" in height.
An 18" frame is most suitable for riders ranging from 5'7" to 6'1" in height.
A 20" or 21" frame works for riders 6' and up.
Keep in mind, these ranges are just approximations. You'll find varying ranges listed elsewhere, as there is no set standard. In reality, no matter your height, people have different builds. Two people of the same height can have drastically different proportions: one might have long legs, while the other might have shorter legs. To be as accurate as possible, you'll want to measure your inseam (standing up, along the inside of your leg from your crotch to the floor.)
"Ok, I've taken my measurements. Now how do I translate that to the bike?"
The frame measurements (16", 18", 20", 21" or what have you) measure the vertical seat tube (not to be confused with the adjustable seat post) on the main frame. The measurement begins from the bottom bracket (the cylindrical part of the lower frame in which the pedal cranks are affixed) and goes up to the top of the seat tube, the point at which the seat post enters the main frame.
Another point of reference would be the following: When standing in front of the seat, the highest point of your inseam should be at least one inch above the top tube of the frame.
Note: The frame measurements are not to be confused with the wheel sizes. Wheel sizes can come in at 16", 18", 20" (most BMX's), 24", 26" (the standard wheel size in the U.S.), and 700C/27" (often found on racing bikes and European models.) The wheel measurements are independent of the frame size; when a bike is labelled as an 18" bike, the measurement is referring to the frame size specifically.