Notice the two small screws on the body of the rear derailleur. (Some Suntour models have three screws. Ignore the top one for now.) The high gear limit screw stops the derailleur from shifting past high gear (smallest sprocket), and the low gear screw prevents it from going past low gear (largest sprocket). If a limit screw is too loose, the chain will fall off. If too tight, the system will not engage the gear.
Locations of the adjustment screws will vary on different brands, but they all function the same way.
1. Tighten the high gear screw, the one that hits a cam when you shift to the smallest sprocket, until you can no longer shift into high gear. Put the shifter in high gear position and while turning the pedals, unscrew the high gear screw until the system engages high gear again. Shift between high gear and the second smallest several times, backing the screw out a little more, just until the derailleur shifts smoothly.
2. Tighten the low gear screw until you no longer get first gear. Repeat the process for this low gear limit - back the screw out just until the bike shifts smoothly from the second largest to the largest sprocket.
3. If you cannot engage high or low gear, or if the above technique does not work for high or low gear, the cable may be improperly adjusted.
Shift into high gear and push the shifter all the way to the end of its travel. Loosen the cable inner wire anchor bolt. That's the bolt with a hole through which the derailleur control wire is clamped. Pull the slack out of the wire, and retighten the anchor bolt.
If your bike has index shifting, you'll find an adjusting barrel either at the derailleur or the shifter. The adjusting barrel is a hollow screw at which the cable outer housing stops, but which the inner wire continues through. Fine adjust the cable tension by turning the adjusting barrel until the clicks on the shifter correspond with proper shifting at the derailleur.
If your bicycle does not engage high gear, or is slow to engage high gear, even though properly adjusted, the cable is probably the culprit. Replace the sticky or rusted cable, and the problem will usually go away.
If you have done everything right, but the bicycle does not shift reliably, the most common reason is that the chain and freewheel are too worn to work properly. If you replace one, you must replace both. A new chain on an old freewheel or visa versa usually skips, and the new part wears out very quickly.
Another possibility is a bent derailleur. The guide pulleys, those little wheels that take up the chain slack, must pivot on the same plane as the freewheel sprockets. Derailleurs become bent when the bike falls over on the right-hand side. Whenever you set a bicycle down, or put it in a car, set it on its left side to protect the derailleur. You can sometimes straighten out a bent derailleur by simply bending it back and readjusting the limit screws.
Update: A reader brought to my attention that there is a third screw that I need to address. This is the "b" screw or "chain gap adjustment" screw. It is located right where the derailleur attaches to the hanger and actually pushes the derailleur back in order for the derailleur to keep from contacting the cassette. Simply move your chain to the largest gear and then adjust this screw to barely keep the derailleur from coming into contact with the cassette. Simple!