One of the most important things to maintain on a mountain bike, or any bike, is the drivetrain. This includes the shifters, chain, front and rear derailleur, the cassette and crankset. All of these parts work together to form your bike's engine. Several of these parts can be responsible for slipping gears, making it important to practice regular maintenance. This will increase the safety and enjoyment of your ride and decrease the chances of getting stuck.
Place your bike in a stand. This will allow you to clearly access all the parts and spin the pedals to see how the drivetrain is performing.
Look over the chain for excess wear or bent links. Using a chain tool, slip each of its ends through the links of your chain and check your chain against its wear indicators. If the chain is worn out, replace it. If a link is bent, either replace the link or the entire chain.
Check your sprockets. The sprockets are under pressure from the chain, especially when climbing. If any of the edges are no longer rounded at the ends and instead resemble a shark's tooth, it's time to replace the cassette because it's probably causing your chain to slip.
Examine your rear derailleur. If the chain and sprockets are fine, chances are this ghost shifting is caused by either a bent derailleur hanger or the derailleur is out of alignment. This is common, especially as new cable stretches, often causing the derailleur to shift incorrectly.
Inspect the derailleur hanger from the rear. The pulleys should line up. If they appear out of alignment, the derailleur hanger is likely to blame for your poor shifting. This is a cheap and easy part to replace, but change it as soon as possible to decrease the chances of it breaking off or flying into your spokes.
Adjust the limit screws on the derailleur with a screwdriver. If the hanger looks straight, adjusting the screws is the next logical diagnostic tool. There is a high- and low-limit screw on the derailleur as well as a tension-adjustment screw. These are marked by an "L," a "B" and an "H." These screws set the parameters on where the derailer can move.
Adjust the B screw until the pulley is rubbing against the largest sprocket. When it is adjusted to just clear the chain, tighten the screw.
Turn to the H-limit screw. First, relieve any pressure on the cable by loosening the cable adjuster. Examine how the chain is riding on the smallest sprocket. If it's rubbing on the next gear, loosen it until it's centered. If it appears to be moving toward the axle, tighten the screw. Readjust the cable tension and see if this solves the problem.
Shift down to your lowest gear and check the L-limit screw if you are still experiencing problems. If the chain is pulling toward the axle as it rides on the sprocket, tighten the screw clockwise until it is lined up underneath. If the opposite is happening and the chain is pulling down, loosen the screw. Before riding, run through all the gears to ensure the derailleur will not shift into the axle.