Fixing a bike chain on the street is no harder than fixing a flat tire if you are prepared.
Step 1: What You Need
To fix a broken chain all you need is a chain tool. These are compact and built into many common multi-tools like the one shown. You may even have one on your multi-tool that you never even knew what it was for!
At home in your garage its possible to repair a chain with just a hammer and pliers, but a chain tool is easier, and really the only option on the street.
Step 2: How Do Chains Break?
The most common way is by pedaling full force at the same moment that you are shifting your front derailleur. Other breaks I've seen were caused by an assortment of seemingly one-in-a-million occurrences, yet i've seen enough of those cases that i guess if you ride long enough one-in-a-million still happens. Things like a nail getting thrown up by my front wheel and lodging in the chain, then getting cranked across the sprocket. who'd a thunk?
Step 3: How Do Chains Work?
Each link of a chain is held together by a steel pin / peg. With the chain tool (or a hammer) you can push out and push in the pins, allowing you to remove or attach links. Fixing a broken chain amounts to removing the broken link and re-attaching the remaining ends. On bikes with derailleurs there's enough extra links that you can remove a couple without a problem. On a single-speed bike you probably won't have enough slack in the chain to remove a link, you'll need to borrow some links from an old chain or else buy a new one.
Step 4: Your Chain Just Broke, Now What?
Are you wearing nice clothes that you care about? Probably best to lock your bike and take the bus home. Come back later with your old jeans and we'll fix it then. Fixing a chain is the dirtiest job there is on a bike.
Step 5: Take a Look at the Chain
Ok you're back and ready to go. Flip your bike over so you can get to the chain more easily.
Take a look at the two broken ends. One end (possibly both) is damaged and needs to be removed. What you will do is to remove 2 segments of the chain at the damaged end. You need to remove 2 segments instead of 1 because the two types of segment alternate. If you just remove 1 segment you can't re-attach it.
Place the chain into the groove in the chain tool (see photo) at the spot you want to disconnect. If you are replacing a worn but non-broken chain you'll do the same thing here.
Step 6: Separate the Chain
Turn the screw on the chain tool to start pushing the pin out of the chain (see photo). be careful to keep the pin on the chain tool lined up with the pin on the chain, sometimes they like to slip around a bit.
Don't push the pin all the way out! Only push it just far enough so the chain comes apart (see photo). You need to leave the last bit of the pin in the chain so you can push it back in later.
If you want to do this without a chain tool: drill a hole in a piece of wood and place the pin you want to remove over the hole. find a machine screw about the size of the chain pin and use it as a peg to bang the chain pin out with a hammer. It's tricky because you don't want to bang it out all the way.
Step 7: Re-attach the Links
OK, now feed the chain back onto your sprockets. It helps a lot if you have a friend who can hold the two ends in position while you reattach them.
Use the chain tool to push the pin back in (see photo). This is the trickiest part to keep the tool lined up with the pin. Note: if you are putting on a new chain here, many new chains come with a special link that makes the first-time installation possible without pushing any pins in.
Step 8: Work It Loose
Once the pin is in, the link you just attached will be stiff. Work it back and forth (see photo) until it loosens enough to bend around the gears.
Take a look at your hands and feel proud. You have done something real today.
Step 9: Reuse
If you were just putting on a new chain in the comfort of your home, now got an old worn chain to reuse! Since you know how to remove links and reattach the segments, you can use part of the old chain as a cable to lock your seat onto your bike. This is very handy in urban areas.
You can also make yourself a bike chain bracelet or an earring. You'll need a fairly big piercing and a tough ear to get that stud through.