So, your beer is ready for bottling. You've waited for fermentation to complete, you know that your gravity is stable. You've sanitized your bottles, your bottling bucket, your tubing. Obviously, your beer is completely flat at this stage, and you certainly don't want it to stay that way.
The next step, of course, is to add priming sugar right before you bottle. Ideally, you'll boil your sugar for a few minutes in a couple of cups of water. Pour this solution into your bottling bucket, then rack the beer on top of it. You should get a nice swirl, which will thoroughly mix your sugar into the beer (some people advocate carefully stirring the beer with a long handled spoon, but I've never had to do this). Don't just dump the dry sugar in, as you pretty much guarantee that you won't get a good mixing of the sugar - definitly use the boiling method instead.
Once you bottle, the residual yeast will eat this priming sugar, which will in turn provide the CO2 necessary to carbonate the beer.
But how much priming sugar should you use? Too little, and the beer will be flat. Too much, and you risk bottle bombs. There are two methods you can use.
Priming Method One: Rule of Thumb
If you're not worried about trying to carb your beer exactly to style, you can simply use the following rule of thumb - one ounce (by weight) of corn sugar (aka dextrose) per US gallon of beer will give you a nice level of carbonation for most beers. Note that if you are using table sugar (aka sucrose), you'll need to reduce this figure down about ten percent.
If you want a little less carbonation, drop it down to three quarters of an ounce of corn sugar per gallon.
This method is fairly foolproof, which is why most homebrew recipe kits include a five ounce baggie of corn sugar for use in priming a five gallon batch. Priming this way gives you a fairly consistent level of carbonation for any beer (about 2.7 volumes of CO2 for a five gallon batch) - which may or may not be what you are looking for.
If you are instead hoping to prime more to style - i.e., you'd like your English bitter to have low carbonation, and your Belgian Golden Strong to be pretty fizzy - or if you would prefer to hit a very specific number of CO2 volumes in your beer, you'll need to use the second method of priming.
Priming Method Two: Calculate the Priming Sugar Needed
One gram of sucrose per liter of beer will give you one volume of CO2. If you feel like doing this the hard way, you can mutiply this all out, but note that you do have to take into account the amount of residual CO2 that is currently in suspension. And of course, if you are using any other type of sugar for priming, you have to figure out how fermentable it is when compared to sucrose, then substitute that factor for our 1 to 1 ratio above.
Fortunately, there is no real need for this much effort. There are many nice priming sugar calculators available online - including one that I'm personally pretty proud of (click for the Homebrew Dad priming sugar calculator). A good calculator does all of the "heavy lifting" for you, and simply asks a very few basic questions (how many volumes of CO2 do you want, how much beer do you have, what temperature is your beer) before giving you some exact amounts of various sugars to achieve the number of volumes of CO2 that you are looking for in your batch.
Unfortunately, one of these questions - the temperature of your beer - is frequently misunderstood. As an answer to this question, people often use fermentation temperature, the expected storage temperature for their bottles, or the temperature at the moment of bottling. While all of these sound reasonable, they are all incorrect.
To properly calculate the amount of priming sugar required, you have to know how much CO2 is currently in solution. Henry's Law lets us know that colder liquids can contain more of a dissolved gas (in our case, CO2). Warmer liquids, on the other hand, hold less dissolved gas.
Why does this matter to us as homebrewers? The answer is that, as long as fermentation is going on, it doesn't really matter. If you don't control your fermentation temperatures carefully, your beer will get warmer during active fermentation, which reduces the CO2 in solution (which then bubbles out of your airlock). However, the CO2 being lost is being actively replaced at this point by the fermentation process.
On the other hand, once fermentation is done, any CO2 lost to temperature spikes is simply gone. You can cold crash your beer prior to bottling, and while that would conceivably allow more CO2 to go into solution, this doesn't actually happen; there is no source of CO2 available.
To make an accurate calculation, you need to use the highest temperature that your beer reached, post fermentation. This allows the formula to properly account for the amount of residual CO2 left in suspension at the time of bottling, which in turn gives you the most precise answer possible in regards to the amount of priming sugar that you should use in your beer.
Finally note that if you are truly shooting for specific numbers, you'll be much happier if you measure your priming sugar by weight (ounces or grams), not volume (cups). Even if you are very exacting and measure a precise volume, you run the risk of your sugar being packed tighter or looser than the calculator assumes, which will result in some minor variances in your end carbonation level.