First, you have to remove the wheel with the flat tire from your bike. If you have a quick release lever installed on your bike, then you just have to flip it open and take out the wheel. If you cannot find any quick release lever, then you will have to loosen the axle nuts holding the wheel. Once they are off, you can easily remove the wheel off the bike frame.
In case you are working on the rear wheel, then you will have take off the chain from the rear sprockets first. Once you are done taking the wheel off your bike, deflate it completely.
Now you need to hook one end of the tire around one of the spokes on the wheel and pry off the tire away from the rim.
You can then slide in a tire iron right beside the first one and move it along the whole rim until you find the tire getting completely free from one side. Now you will have enough space to remove the old tube from it. You will have to loosen the nut on the tube valve before taking it out.
Take a new tube and insert it in the tire, in a way that the valve matches the position to the valve hole in the rim. Insert the valve in the hole and place the nut to hold it in place.
Remove any twists from the tube and make sure it is lined up properly against the inner side of the tire. Also, you can inflate the tube slightly and the remaining twists will automatically be removed from it.
Using your hands, put back the loosened side of the tire back in the rim, as much as you can. You can then put the tire iron inside and use it as a lever to put back the remaining part of the tire.
Inflate the new tube completely and then put the wheel back on the bike.