The one everyone quotes is Sheldon Brown's, also used by Park Tool:
L = 2C + F÷4 + R÷4 + 1
L is chain length in inches, C the chainstay in inches, F the largest chainring and R the largest cog. The +1 is slack for the derailleur cage to take up. Divide L by 0.5 for links, since every bicycle chain has a half-inch pitch, then round up to an even number — a chain joins in inner-and-outer pairs.
It is an approximation and a good one. Against the exact loop geometry it lands about 0.8–1.0 inch longer than a bare big-big wrap, which is the same allowance the shop method tells you to add by hand. On a single speed that approximation is no use, which is why this calculator switches to solving the loop exactly when you pick that mode.