The alcohol content in homebrew can be determined by comparing the specific gravity of the beer before fermentation to the specific gravity of beer after fermentation. When you add yeast to your wort it will convert the dissolved sugars into ethyl alcohol. I always think of it as the yeast eats the sugar and poops out alcohol and carbon dioxide. Much easier to remember than each glucose molecule converts into two ethyl alcohol molecules and two carbon dioxide molecules. Because the yeast converted some of the sugars in your wort to alcohol, which is less dense than water, the final gravity reading will always be less dense than the original gravity.
During fermentation the carbon dioxide will bubble out of your airlock and the alcohol stays behind. The molecular weight of carbon dioxide is 44.01g/mol and the molecular weight of ethyl alcohol is 46.06844 g/mol, so for each gram of carbon dioxide that leaves your bubbling fermenter, 1.05 grams of alcohol are left behind.
Lets say you brew a pale ale with an original specific gravity of 1.050 and an ending specific gravity of 1.010. If you subtract your ending gravity from you original gravity that will give you the amount of carbon dioxide that has bubbled out, .04 in this case. You then multiply the weight of ethyl alcohol, 1.05, to get the weight of alcohol in your fermenter. Now that you have the weight of the beer and the weight of the alcohol you can calculate the percent of alcohol by dividing, .042/1.010 which is 4.1% ABW.
ABW = ((Original Gravity - Final Gravity) * 1.05) / Final Gravity
ABW (Alcohol by Weight) will always be greater than ABV (Alcohol by Volume) because an equal weight of alcohol will take up more space than the same weight of water. A pound of beer takes up more space than a pound of water. To convert ABW to ABV you just need to divide by the density of ethyl alcohol which is 789.00 kg/m³ or 0.79.
ABV = (((Original Gravity - Final Gravity) * 1.05) / Final Gravity) / 0.79
Remember that the final gravity is calculated based on the attenuation of the yeast. Here is more information on calculating the final gravity.