When you shift your gears you move a lever that pulls a cable. This cable moves your derailleurs. The derailleur moves your chain over the appropriate gear. The chain is prevented from going too far in either direction by properly adjusted derailleur stops.
An improperly adjusted derailleur causes over-shifting (when your chain shifts off the cogs or chain ring); under-shifting (when your chain won't shift into the next gear) or automatic shifting (when you haven't even touched the lever). A properly adjusted derailleur hits all your gears quietly, quickly, and precisely while you pedal.
To adjust your derailleur, it helps to have a bike stand to get your bike off the ground. If you don't have access to one, you can hang your bike by its seat and handlebars. First, pull the right hand thumbshifter all the way back towards you while cranking the pedal forward. The chain should be on the smallest cog in the rear. If it's gone past and over shifted between the cog and frame, you need to set your outside derailleur stop. This is done by tightening a screw marked"H" (for high gear) on the derailleur. Carefully lift the chain back on to the smallest cog. Then, turn the "H" screw clockwise with a small slothead screwdriver until you meet resistance. Do not over tighten. If you are under-shifting and not reaching the small cog, you need to loosen (turn counter-clockwise) the "H" screw until the chain engages on the cog.
While you have the chain on the small cog, check your cable tension. Loosen the bolt that holds the cable to the rear derailleur.
Grasping the end of the cable with a pair of pliers, gently pull the excess cable slack and retighten the binder bolt.