Swapping an innertube is at the heart of repairing a flat tire on a bicycle - but while you've got the rubber off the rim, it's important to check 3 other things too -- so you don't get another flat any time soon.
So, you've got your new innertube and you've just removed the tire from your bicycle wheel. To make the most of your repair, and to make sure it goes the distance, make sure you inspect these three things --
1. Check The Tire
The tire may have debris stuck in it. Think thorns, tacks, staples, or even very small wires. Get a magnifying glass and examine the inside and outside of the tire to make sure no small debris will cause you another flat. Once you located it, grab your needle-nose pliers and pull it out. But don't stop there, because there could be more than one piece of debris. Keep searching until you're sure there's nothing more.
Then, check the beads of the tire. Those are the circular inner wires of the tire that rest against the insides of the rim when the tire is inflated. If the beads have a flat spot that prevents the tire from being perfectly circular, throw the tire away and get a new one. Flat spots in the bead will lead to more flat tires. The way to prevent such flat spots is to make certain the bicycle never sits on a flat tire for more than a few hours. Any longer, and you risk flattening the bead and ruining your tire.
2 - Check the Rim
The rim itself can be a contributor to flat tires too, if it's damaged. Make sure the outer part of the rim, the sidewall, is perfectly round and has no damage or big scrapes. If it does, consider purchasing a new wheel (or lacing a new rim--not for beginners). Then make sure there are no burrs or sharp spots on any of the spoke nipples. If everything looks and feels clean, you're good to move on to the rim strip inspection.
3 - Check the Rim Strip
The rim strip is the plastic, rubber, or fabric tape that rests between the rim and the innertube. Check to make sure the rim strip is completely intact and has no tears or holes. If it's a plastic or polyester rim strip, make sure it has no sharp spots sticking up that could puncture the tube under full inflation. Finally, make sure the rim strip is covering all of the spoke nipples (or spoke holes) completely. An exposed spoke nipple or spoke hole will certainly ruin your new innertube.
Once you've checked (and if necessary, remedied) all of the above, you're good to go to install that tube and get your tire seated.