This is a simplified explanation based on Palmer's How To Brew:
To understand (calculate OG), first calculate your "potential" gravity points (PGP).
As an example, let's say I'm making a simple 5-gallon batch of Stout with the following grain bill:
8 lbs. Pale Malt (1.036 potential = 36 gravity points)
1 lb. Roasted Barley (1.025 potential = 25 gravity points)
PGP = Grain Gravity Points * Weight / Volume
PGP = (8*36) + (1*25) / 5
PGP = 62.6 (which, in gravity looks like 1.063)
This is only a "Potential Gravity" that is impossible to actually hit on Brew Day
----------------------------------------------------------------
Expected Original Gravity (OG) = PGP (points) * Brewhouse Efficiency %
...where Brewhouse Efficiency is based on our average measured BE over all previous brews. This could be anywhere from 65-85% or even outside that range.
From the example above, using my BE:
Expected OG = 62.6 * 72% (.72)
Expected OG = 45.1 = 1.045
---------------------------------------------------------------
Now, let's say after brew day, I measure my OG as 1.048. To calculate my Brewhouse Efficiency for this batch it would be:
Efficiency = Actual OG Measured in Points / Potential Gravity Points
Efficiency = 48/62.6
Efficiency = 77% for this Brew Day (this can be used as another efficiency data point when calculating Expected OG for future brews.)
The key to the whole thing is to understand your efficiency, which comes with taking good notes, brewing batch after batch, and dialing in your system