Every cyclist gets a flat tyre once in a while. The good news is that a prepared cyclist can easily fix the puncture and get back on their way quickly and without a lot of bother. Once you learn to patch a tube, you can travel as far as your pedals can take you (assuming, of course, that no other mechanical difficulties hinder you).
Most bicycles, whether road, off-road, or cruisers, use clincher tyres. The clincher system has a thick rubber tyre that fits into the rim of the wheel. The tyre contains an inner tube that holds air under pressure. Air enters the tube through a valve, of which there are two kinds, Presta and Schraeder1. The inside of the rim is covered in rim tape so that the nipples of the spokes don't poke holes in the tube. The edges of the tyre are lined with wires to hold onto the rim; this is called the bead.
Your Tool Kit
Your tool kit should include the tools you need to fix a flat tyre on your bicycle and not much more than that. You can get a nifty little under-saddle bag to stow these things in, or you can keep them in a pocket, or in the bottom of your rucksack. The tool kit should consist of the following:
A pump set up to inflate the kind of valve - Presta or Schraeder - that your wheels have
Tyre levers, which help lift the bead off of the rim
A patch kit, with extra patches, rubber cement, and a piece of sandpaper or a buffer
A small piece of tough fabric (denim or canvas), about one inch square, to place underneath a big gash in the tyre
A spare tube or two with the same valve as the one already in your tyre
A 15mm or adjustable wrench, if your axle does not have quick-release levers
A pocket knife, the blade of which can be used to release air from Schraeder valves
Different Kinds of Flats
Most flats are caused by a sharp object that sticks in your tyre and punctures the tube. This happens more often on wet days than on dry ones, because the water and oil on the road make objects stick to your tyre. Sometimes you get pinch or snakebite flats, where the tube is compressed and rips in two places. This means that all the air goes immediately out of the tube. You can try to avoid snakebites by keeping your tyres at full inflation (listed on the tyre wall) and by avoiding riding over deep potholes or trenches because riding over the edge of the far side of the trench can compress your rear tyre.
Your tube can also burst (leaving a huge irreparable rent in it) if the tube gets improperly caught in the rim, if you over inflate the tube, or if you leave your bike in focused direct sunlight. If the tube bursts, you have to replace it with a new one.
Fixing the Flat
Use the tyre levers to pry the tyre off the rim2. Keep one bead of the tyre within the rim to keep the tube and wheel aligned. Use only tyre levers and not screwdrivers or your pocket knife for this task so that you don't scratch up or deform the rim.
Starting opposite the valve, pull the tube slightly out of the tyre. Don't go all the way; keep the tube near the corresponding part of the tyre so that you can find the object that caused the puncture. If you are just going to put on a new tube, omit the next two steps, but don't forget to find the sharp thing in your tyre, or else you will be changing your tyre again all too soon!
Inflate the tube slightly using the pump. Go around the entire tube to look for the puncture. It is actually easier to hear the whoosh of escaping air or to feel the air on your cheek than to spot the hole visually; holding the tube next to your ear is a good tactic. If you cannot find the puncture, remove the tube entirely from the wheel, fill a basin with water, and submerge the tube. You will see the bubbles of escaping air from the puncture.
When you find the puncture, scrape the area around it with the buffer. This cleans the rubber and roughens it so that it takes the patch better. Cover the area with a big dollop of rubber cement (from the patch kit); make sure that the area covered is greater than the size of the patch. Larger holes need bigger patches. Wait about five minutes for the cement to dry.
While the cement is drying, look for the sharp object that caused the puncture. If you remember how the tube was lined up with the tyre, it shouldn't be hard to figure out which section has said object in it. Take a piece of cloth (or glove or shirt) and run it along the inside of the tyre; it will stick on the protruding object that punctured the tube. Remove the object. If there is a large gash in the tyre, place the fabric square between the tube and the tyre under the hole in order to keep new debris from lodging in the hole and puncturing the tube again. If you have no piece of fabric, try a currency note instead.
By now, the cement should be dry. Peel the silver foil off the patch and apply that side to the tyre. Rub hard from the centre toward the edges so that it sticks really well. Leave the cellophane on; it helps protect the patch.
Inflate the tube slightly and pack it back into the tyre, starting at the valve, which you can line up with the tyre label. Squeeze the bead of the tyre back into the rim of the wheel. Inflate the tube a little more and make sure that the bead is within the rim all the way around. If it has slipped out anywhere your tube will be squeezed against the rim and will burst; you will then have to replace it with a new one.
Before fully inflating the tube, put the wheel back onto the bicycle by inserting the axle into the dropouts. When the wheel is fully in place, inflate the tyre to the same pressure as the other tyre on the bike. Do not use car-style air pumps available at filling stations; they are meant for larger tyres and deliver air more quickly, which could burst your tube. Before you finish, tighten the bolts that hold the axle onto the bike by turning and flipping the quick-release levers or with your wrench.
People tell of stories during the war when tyres were sometimes stuffed with grass, due to the relative expense of inner tubes. These days, this trick would obviously be a last resort, but it can come in handy. If you are in the city and there is no grass nearby, look around for broken or abandoned3 bicycles. You can ransack these for tubes; look for the valve sticking out of the rim before you remove the wheel and discover that someone has already taken the tube. Make sure that the valve fits your wheel; a Schraeder valve will not fit a Presta-drilled wheel. Another nifty last-ditch trick is to cut the tube at the hole and tie the two ends together and inflate that.
Do not attempt to ride on a flat tyre. You may be able to roll forward but you are putting your tyre and your rim at risk, and both of these cost more than a new tube.
Avoiding Flat Tyres Altogether
Keep your tyres inflated to the proper pressure. The pressure is listed on the tyre wall of each tyre. In general, knobbly mountain-bike tyres are inflated to 40-45psi, slick tyres to 70-90psi, and skinny racing tyres to 115-120psi. Air will leak from the tyres slowly, so if you haven't ridden in a day or two, inflate tyres to proper pressure before a ride. Regular cyclists are advised to invest in a decent floor pump: they are inexpensive and make inflating tyres to the correct pressure easy.
Also check your tyres for sharp objects after a ride, particularly after travelling through patches of glass or thorns and after wet days. Objects can lodge in the tyre harmlessly at first. After several more miles of riding, they may work through the tyre and puncture the tube.
Thornproof tubes are available and are moderately effective; the downside is that they are much heavier and more expensive than ordinary tubes. They are not completely impervious, though, as screws and nails will puncture them. Thornproof tubes can be temporarily patched with ordinary patches, so keep the patch kit handy just in case.
Some bike shops also sell plastic strips that go inside the tyre to keep sharp objects from puncturing the tube. However, these may rub against the tube and cause friction flats. For restaurant-delivery riders and other people who literally cannot afford to patch or change a tube, solid-plastic tyres are available at some shops. These have no air inside them so cannot go flat. The drawback is that they are heavy and noisy and the plastic does not give as smooth a ride as the inflated tube.
Chemical products also exist to address this problem. One kind of aerosol is called Slime. It adds a self-sealing layer to the inside of the tube so that any puncture will close itself up and can be applied either preventatively or after the puncture. Its drawback is that it destroys the inner tube within 12 months, after the Slime goes hard.