It's inevitable, if you ride a bike you're going to get a flat tire sooner or later. Changing a bike tube can be quick and painless, but you'll need a little know-how and practice. Pro-tip: there are also a few ways to prevent them before you start your ride.
Prevent Flats Pre-Ride
Most of the time flats can be avoided with just a little routine maintenance. The first thing you want to do is inflate your tires before every ride to prevent pinch flats. When tires are under-inflated they tend to bottom out on large rocks or holes in the road, which will pinch and puncture the tube between the rim and tire.
Keep your bike within the recommended pressure. Usually road bikes will have recommended pressure between 80-120 psi, make sure to read the sidewall of your tire to see what is recommended for your tire. Use lower pressure for improved grip in bad conditions and if you are heavier you will need more air in your tires. NEVER go over the maximum recommended psi!
Pack the Perfect Flat Kit
I, and many other cyclists, have learned this the hard way. ALWAYS be prepared for a flat when you are out on the road. The worst thing that could happen is you get stranded 15 miles from home with no money, no phone, no supplies to fix a flat.
Always ride with a tire lever (2 makes it easier), patch kit, spare tube, and some way to inflate your tire. I prefer using C02 to inflate my tires because it takes up less space, but frame pumps last longer than one use and are a bit more reliable. You should always bring money with you, but I'll get to that later. Most riders prefer to replace the tube entirely, but patching the tube is perfectly acceptable if you are keen on saving a few bucks.
Sometimes mechanical failures happen, so it's a good idea to bring money on you. However, a dollar bill can used for more than just currency. If you have a tear in your tire from the flat put the dollar bill between the tire and the new tube. This will prevent the new tube from popping through the tire once it is inflated.
Find the Cause of Your Flat
If your rear wheel went flat, it is best to shift down into your smallest cog on the rear cassette. This makes it easier to get the wheel off and back on.
Make sure your tire is deflated all the way by opening up the valve and squeezing. Then, pry off the first tire bead with a tire lever or two. Tires are made to be stiff so it might take a few tries. Then run the lever around the rim to unseat the tire from the rim. I like to leave the other bead in the rim instead of out as it makes putting everything back together a lot easier.
Remove the old tube. Then, run your finger along both the inside and the outside of the tire to make sure whatever caused the puncture isn't still imbedded in the tire. Be careful because there could be a piece of sharp debris or glass! Also take this time to make sure your rim tape didn't shift, an exposed spoke hole could cause a puncture.
Install and Inflate the New Tube
Now it's time to seat the new tube in the tire. I find it easier to inflate the new tube just a bit by blowing air into the tube with your mouth. Make sure to close the valve once you are done blowing.
Now seat the tube in the tire on the side of the tire where the bead is out. Make sure to place the tube in the correct position, paying attention to the valve, and making sure not to twist the tube.
Next, work the bead back onto the tire. Avoid using a tire lever for as long as possible as it could pinch the tube between the rim and tire which will cause a pinch flat. Also, make sure that the area around the valve is not the last area you put back on the rim. This could potentially damage the valve or tube.
Do a quick inspection of the walls of the rims between the tire by pinching the sidewalls of the tire together. You should be able to see if part of the tube is trapped between the tire and rim.
If everything looks good then you are ready to inflate. Make sure to wait a minute or two to ensure that the new tube does not go flat due to improper installation. Now, put your rim back onto your bike and you are ready to ride!