Mountain bikes just keep accumulating more gears. Today, some bikes have as many as 27 gear ratios. Mountain bikes use a combination of three different-sized sprockets in front and nine in back to produce these gear ratios.
The idea behind having all of these gears is to allow the rider to crank the pedals at a constant pace (cadence) no matter what kind of slope the bike is on. You can understand this idea by imagining a bike with just one gear. On this one-gear bike, each time you rotate the pedals one turn, the rear wheel would rotate one turn as well (a 1:1 gear ratio).
If the rear wheel is 26 inches in diameter (66 cm), then with 1:1 gearing, one revolution of the pedals would cause the wheel to cover 26 * 3.14 = 81.6 inches (207 cm) of ground. If you are pedaling at a cadence of 50 RPM, that means that the bike can cover 81.6 * 50 = 4,080 inches (340 feet) (103 m) of ground per minute. That is only 3.8 MPH (6.2 KPH), which is about walking speed. That's great for climbing a steep hill, but bad for level ground or downhill stretches.
To go faster, you need a different ratio. For example, to ride downhill at 25 MPH (40 KPH) with a 50 RPM cadence at the pedals, you need about a 6.5:1 gear ratio. A bike with lots of gears gives you a large number of increments between a 1:1 gear ratio and a 6.5:1 gear ratio so that you can always pedal at about 50 RPM (or whatever cadence feels comfortable to you) no matter how fast the bike is going.