FV(A) = A * ((1 + i)^n-(1+g)^n) /(i - g) (it's easier to see in the wikipedia link)
Where:
A = starting money
FV(A) = future value of money
i = interest rate compound over each period (for instance, per year you might assume 4% interest after inflation)
g = the amount you are contributing per period (for instance, 20,000 per year)
n = the number of payment periods
...
From the wikipedia link referenced (and it is a good one):
FV(A) is the value of the annuity at time = n
A is the value of initial payment paid at time 1
i is the interest rate that would be compounded for each period of time
g is the growing rate that would be compounded for each period of time
n is the number of payment periods
This is the formula for the future value of an annuity immediate where your contributions increase by a percent, g, each period. You might use this to simulate a percent raise every year, but the percent raise would not quite be equal to g unless you base the percent raise on your current savings amount instead of your gross income, effectively giving yourself a bigger and bigger raise each year as a percent of gross assuming that your expenses stay fixed.
What you actually want is the formula for the future value of an annuity immediate, which is
FV = R*((1+i)^n - 1)/i,
where FV is the future value, R is the amount of each contribution, i is the effective growth rate per period, and n is the number of periods. Make sure your periods for n match your periods for i and R. This formula assumes a constant growth rate and the same contribution amount during each period.
Incidentally, this can lead us directly to the formula arebelspy provided through a tiny bit of algebra. Based on our expenses, E, and our SWR we need E/SWR in future value to be FI. Substituting into my above formula we get
E/SWR = R*((1 + i)^n - 1)/i.
Now we just need to solve for n.
E/SWR*i = R*((1 + i)^n-1)
E/SWR*i/R = (1 + i)^n - 1
E/SWR*i/R + 1 = (1 + i)^n
Ln(E/SWR*i/R + 1) = Ln((1 + i)^n)
Ln(E/SWR*i/R + 1) = n*Ln(1+i)
Ln(E/SWR*i/R + 1)/Ln(1 + i) = n,
which is simply arebelspy's formula with my variable names.
Note that n can be any period of time as long as you use the same period to determine the value all other variables. For example, you might use the expenses and contribution amounts from your biweekly paycheck, then use .04/26 = .00154 as the biweekly SWR, and (1.07)^(1/26)-1 = 0.2606% for your biweekly growth rate which would produce a biweekly n that would need to be divided by 26 in order to convert to years to FI. The smaller your contribution period, the smaller your time to FI will be unless you use a negative growth rate.
The biggest issue is it assumes spending now = spending in the future. I use methods that allow a different ER spending than current spending (DoubleDown's suggestion should, I believe, allow this).
:)
FYI, it is perfectly acceptable to use your expected retirement expense levels instead of your current expense levels in this formula since the only factor affected by the expense variable is the one that gives us our goal for the FV variable which should be based on your expenses in retirement, not your current expenses.
If you want to include your current account balances in this calculation, use the more general formula
(Ln(E/SWR+R/i) - Ln(P + R/i)))/Ln(1 + i) = n,
where P is your current investment account balance. Or
=(LN(A3/A4 + A2/A1) - LN(A5 + A2/A1))/(LN(1+A1),
in arebelspy's variables with the addition of A5, the current investment account balance. Note that the special case where P = 0 can be simplified to the above formula where current savings levels are not included.