PS (grams) = 15.195 Vb ( CD - 3.0378 + .050062 * T - .00026555 * T * T );
where Vb is volume of beer in gallons, CD is carbon dioxide concentration in the final brew in volumes, and T is temperature at bottling.
Desired value of CD is 2.2 to 2.6 for most beers, 1.8 to 2.2 for British ales, 2.5 for lagers and German ales, 2.6 to 2.8 for American beers, and 3.0 for wheat beers and fruit ales.
To plug and play, go to this Online Carbonation Calculator.
This calculation was also taken from Michael L. Hall's article Brew by the Numbers: Add Up What's in Your Beer (Zymurgy, Summer 1995, vol. 18, no. 2).
OG in points = (Points) * (lbs of malt used) / (gallons of beer brewed)
for each ingredient that adds to the density of the wort. For malt extracts, "Points" = 35 for syrup (in practice it's about 30) and 42 for dried extract. For speciality grain contributions, Pale Malts = 29 points, vienna/munich/amber = 25, wheat = 26, cara pils = 20, crystal = 8, black = 2.
To get a result in the traditional 1.xxx form, divide your OG "points" result by 1000 and add 1. So, 40 would become 1.040.
For example, let's say I use 7lbs of liquid extract and 1lb of cara pils, my estimated OG for 5 gallons will be:
OG = ( 35*7 + 20*1 ) / 5 = 53 (or 1.053).
As another example, if I want to target an OG of, say, 1.062 I could determine the needed amount of liquid extract:
62 = (35*x + 20*1) / 5, then x = 8.28 lbs of liquid extract.