Remove the chain from the bike using a chain tool.  If you ran your bike through mud and your bike just got completely coated, then you should probably do it this way to effectively clean the chain.  Preplan ahead and make sure you have a replacement chain pin, or that you will leave the chain pin partially inserted in one link so that you can reinsert the pin using the chain tool.  Shimano does not recommend using the same pin
cleaning the drivetrain

The drivetrain is where dirt accumulates first and fastest on the bike.  It is also important to keep it clean so that your shifting will be smooth.  A dirty chain is the #1 reason why the rear cassette and front chainrings wear our prematurely.  There are basically 3 methods you can choose to clean your chain:

Just using a rag.  This is the easiest method, the method that is best used after a ride that is especially dirty or wet and the method which is least effective.  Use a lubricant like WD-40 to spray on the chain, place a rag in one of your hands and grab the chain from the bottom while rotating the chain through the gears.  The chain running through your rag will leave some of the dirt and grease on the rag.  Repeat as many times as it takes with relubing the chain each time.  Be sure to wipe off the excess WD-40 when you're finished as this type of lubricant, a wet lubricant, attracts the most dirt to a chain.

Use a chain scrubber such as the ones made by Finish Line.
This apparatus allows you to leave the chain on the bike and clean
the chain in a similar way as using a rag but instead of a rag, the
chain will run through the chain scrubber which contains a cleaner
solvent and small brushes.  This method is very effective and my
favorite.
1.  First try to find the location of the puncture.  You'll have to ensure that the puncturing object is fully removed, including from inside the tire.  If you can't find the puncture site, don't sweat it.

2.  Remove one side of the tire off of the rim.  You'll probably have to use at least
one tire lever.  Use two if the tire's fit is especially tight.

3.  With one side of the tire off of the rim, you can pull out the inner tube.

4.  Carefully run your fingers along the inside of the tire.  Especially at the site of the puncture to ensure that any puncturing objects are removed.  Be careful to not puncture your own finger with the offending object!  Also check the rim tape to ensure it's not the problem.  The purpose of rim tape is to prevent the spoke from puncturing the tube.

5.  Feed the air valve through the wheel's hole and place the new inner tube into the tire.

6.  Work the side of the tire back onto the rim.  You should be able to pull the last portion of the tire bead onto the rim with your fingers.  Don't use your fingernails, it really hurts if you tear one off.  If it's really tight, use a tire lever.

7.  Here's an important step, as you air up the tire, check to make sure that the tire bead is staying on the rim.  If any portion of it comes off or the tire bulges asymetrically then the tube could be exposed to pop out from under the tire and if that happens...BOOM!!!...you get to replace the tube (the hole will be way too big to patch).
maintaining your ride
Don't let a flat stop your fun.  Let's replace the flat tube!  If I'm riding on the road, I will replace the inner tube with one of my spares.  This is the fastest way to get back on the road.  Save the punctured tube for repair later and if you happen to have another flat on the road on the same ride and no more replacement tubes, then you'll at least have some tubes to repair.
replace a tube
By the way, an inner tube can essentially last forever.  How many times can it be repaired?  There is no limit as long as you can repair it so that it doesn't leak.  In light & responsive bikes with narrow & light tires, you might be able to feel a slight lump where the patch is on the tube when you're riding; if that bothers you, then replace the tube.
repairing a punctured tube

The rubber patch is going to have to be able to cleanly lie flat on the tire.  If the puncture is within 1/2 the width of the patch's diameter to the valve then it is most likely not patchable. 

1.  Locate the puncture point by inflating the tube (try blowing it up with your mouth if you have no other air source) and listening for the leak or appy some fluid like water or even spittle to detect escaping air bubbles.
2.  If the puncture is near a seam or ridge on the tube, then it won't be patchable until you sand down the ridge area at the puncture so that the rubber patch can lie flat on the tube.

3.  Ensure the area of the puncture is clean and dry.  Pay attention...this is THE biggest mistake made by newbies...apply a LITTLE glue to te puncture area.  Do not apply so much that it obviously beads up on the tube.  Think of just wetting the area with the glue as if it were water with a thin layer.  The reason for this is that the glue MUST dry before the patch is applied.  And if you put too much glue on, it will be quite a while before it will dry.  Ordinarily it should take about 5 minutes for the glue to dry.

4.  Other patches may work slightly differently, but I'll describe the most common variety which is the type of patch shown above with the orange circle as shown above.  The rubber patch has foil on one side of it and a clear plastic film on the other.  Peel the foil away from the patch, being careful to leave the clear plastic film on the patch.  It won't always be easy to do this, but try your best without damaging or folding the patch onto itself.  Once the foil is removed, the rubber side of the patch facing you should be the smooth side of the patch.  The rougher side is still covered by the clear plastic film.
repair a flatted tube
all about wheels
front & rear derailleur adjustment
cleaning the drivetrain
over again, but I know of several people that have always reused pins.  It just depends on whether you want to buy & keep some pins in stock with you. 

Chains commonly come in 8 or 9 speed widths.  The speed refers to the # of gears you have on the rear cassette (see pic below).  There are older models still available, even down to 5 & 6 speed.  As the number of gears (speeds) are increased, there has to be a give and take on the rear axle length.  If you, as a bike manufacturer, were to make an 8 speed bike into a 9 speed by simply adding one more gear to the rear cassette, you'd have to ensure that your bik'es rear triangle was wide enough to accomodate the increased rear axle length.  This is not desirable as this would mean that all bikes would then have to be built to a new standard and current owners could not upgrade their bikes as it would mean replacing the frame.  Instead, the better idea would be to make the gears on the rear cassette thinner than before so that 9 gears fit into the same space as 8 gears would.  This would mean a decreased chain thickness too.  That's what they did to allow for the current bikes to use either 8 or 9 or even 10 (Campognolo only) speed gearing by just upgrading your drivetrain.  This also means that the chain tool you are using must be designed for the width of chain on your bike.  Most chain tools come with two widths on them: 8 & 9 speed.  Note the chain tool above has two slots on it, with the chain placed in the bottom slot.  That is the 9 speed slot.  Once you place a chain into the wrong slot, it's obvious to note that it's either too loose or too tight.

Once the chain is removed from the bike, you can soak the chain in a solvent such as Varisol or other petroleum distillate.  This is the most effective method to remove grease and grit from the chain.  You can soak it and shake it around in the solvent for a few minutes or even let it sit in the solvent overnight.  Replace the chain onto the bike and it's good to go!

Speaking of chains...How do you know when you need to replace your chain?  Well, the rule of thumb is to grab a stiff ruler that is at least 12" long.  Place the 0 mark on the ruler over the center of a chain pin.  The 12" mark should be directly over a chain pin 12 links away.  (Don't worry about counting the links; chains don't stretch that much, so it will be 12 links plus or minus 1/8" of an inch.)  If the 12" mark of the ruler is more than 1/8" from the center of a chain pin then it is time to replace your chain.

Oh...see that plastic comb-like tool with the triangular teeth with the brush
next to the chain scrubber above?  That's what you use to get in between
the chain rings on the front and rear cassettes unless you're going to
remove those from the bike for soaking also.
HOME
BACK to Bike Info
when do I replace my chain?
If you've already dragged out solvent to soak your chain.  Then you might as well make good use of it and soak your rear cassette too.
Just for information, this is also called a freehub.  The term freehub is actually a Shimano patented term.  Before freehubs, there were just freewheels.  Freehubs & freewheels both allow us to coast while not rotating the crank.  The set of bearings in the freewheel spin around the axle while the freewheel remains stationary, along with our chain and our crank.  The freewheel contains these bearings as part of its structure.  Shimano improved upon this design by moving these bearings into a hub structure that is affixed to the axle.  The below diagram illustrates a Shimano freehub.  A Shimano cassette would fit onto this freehub.
removing the rear cassette
There are a number of various types of gear manufacturers and styles available.  I'm going to discuss removal of a Shimano Hyperglide cassette.  If your bike is '99 or newer, has higher end Shimano components and has either 8 or 9 speed rear cassette then you very most likely have Shimano Hyperglide cassette.
To remove the Shimano rear cassette, you'll need two special tools.  One is the socket that fits into the cassette body that will unscrew the lockring.  The most popular manufacturer of this socket is Park Tool and the socket for Shimano Hyperglide cassettes is the FR-5, which is pictured below middle.  The second special tool you need is a chain whip.  Pictured below left, it is used to hold the cassette steady to keep it from spinning while you remove the lockring.  The diagram illustrates the direction you want to turn the socket to remove the cassette.
Once you remove the lockring, you'll find that the lockring is also the littlest gear on the cassette, as shown below.  You'll also note that 4 of the smallest gears will come off individually while the remaining gears are locked together. 
There will also be metal ring spacers between each gear.  Don't worry about which one goes where, they are generic and each one will fit between any of the gears.

When you go to put the rear cassette back onto your bike, you'll notice that the gears fit only a particular way onto the hub because of the splines.  And there is one spline which is wider than all of the others.   But do make sure to orient the individual gears with the correct side facing up.  Take a look at how the teeth on the individual gears are cut with little ramps and compare them to the larger gears which are fixed together.  It should be fairly obvious which side is the correct side to face outward.  Be sure to put a spacer between each gear.  There is no spacer between the smallest gear and the second smallest gear as the smallest gear is wide enough already to accomodate the chain width.
Once you've placed the gears back onto the freehub, like puzzle pieces, you'll tighten the cassette with just the FR-5 socket in a clockwise direction.  You won't need the chainwhip to hold the cassette this time.
5.  Place the rubber patch's smooth side onto the dried glue area while continuing to leave the clear plastic film on the patch.  Smooth the rubber patch so that it is flat and even on the tube.  Apply pressure to stick it to the tube and then lay the tube with the applied patch carefully aside to allow it to dry for about 5 minutes.

6.  Carefully peel away the plastic film from the patch.  Your tube should be good to use now.
bike anatomy