Drivetrain (thorough version)
Take the rear wheel off and grab the upper portion of the chain with a degreaser-soaked rag. Use your hand to turn the crank while squeezing the chain to remove grease. It might take a couple of rags to clean it sufficiently.
Take the chainrings and cassette off the bike and drop them into a bucket of degreaser. Let the components soak for a few minutes before pulling them out of the bucket and scrubbing each ring with a rag to remove the black, caked-on grease.
Grab a rag with degreaser and scrub the derailleur pulleys between your fingers.
Chainrings have features that help the chain jump between rings, and they work best when specifically oriented, so chainrings have markers that indicate how to situate the rings on the crank. Make sure this marker lines up with the crank arm. Put a drop of blue Loctite on the chainring bolts so they don't wiggle loose and tighten them firmly. Lock the cassette back onto the wheel and reattach onto the bike.
Drivetrain (quick version)
Pull the rear wheel off the frame and spray cleaner or chain lube onto the cogs. Take a rag and floss between the cogs. Clean the derailleur pulleys between your fingers with a rag. Scrub the crank's big ring with your towel. The small ring is difficult to clean while on the bike. Put the rear wheel back on the bike, sprinkle lube onto the chain and grab the lower portion with a rag. Pedal backward while gripping the chain to scrub the grease off.
Polish the Bike
It won't make your bike function more effectively but, if we're honest with ourselves, bikes are expensive toys, and expensive toys should be kept pretty.
Spray mild cleaner on the bike and wipe it down with a rag. You can also use a hose to take dirt off, but be careful to keep the stream away from the hub, bottom bracket, derailleur and headset bearings so their lubricants don't get washed away.
Keep Your Bolts Clean
Whenever you pull a bolt off your bike, apply a little metal grease to the threads to prevent the bolt from corroding.
Keep Your Cables and Housing Clean
If dirt, grease or sports drink get into the shift housing—the tubes that connect your shifters to your derailleurs—the cables will not slide properly, which ruins shift performance. There is no good way to clean the housing once it's dirty, so replace old housing every year or two. People living in a rainy climate should change theirs frequently.