The reason bikes have so many gears (20 to 27) is to allow the cyclist to maintain close to the same cadence through the many variations of off-road terrain.
As you go up hills you should continue to downshift into progressively lower gears to maintain your rpm’s. As the hill flattens out you should start shifting into higher gears, and so on. The cadence should be maintained at a minimum of 70 rpm’s – some say as high as 100 rpm’s. This means that in 10 seconds one of your pedals would go through 12 to 16 complete revolutions. Pedaling at lower rpm’s puts unnecessary strain on your knees and leg muscles.
Your pedaling should also be a steady, fluid motion (imagine yourself pedaling in a circle) and avoid pushing harder on your down strokes. This will allow your pedaling power to be provided smoothly to the rear wheel and will help minimize spin-out of your tire. The use of clipless pedals improves this by allowing you to pull up on the return stroke and get power out of the full 360 degrees of pedal rotation.
By maintaining a reasonably constant cadence you’ll also be better able to maintain a constant heart rate – ideally at a level where you’re getting an aerobic workout. You want to avoid constantly going anaerobic – that state where your body is using up more oxygen than its being provided (like in any type of sprint). This will only burn you out prematurely in your ride.
So, remember, get those rpm’s up and keep them constant.