401(k) Calculator Formula

Understand the math behind the 401(k) calculator. Each variable explained with a worked example.

Formulas Used

Projected 401(k) Balance

future_value = current_balance * pow(1 + r, years_to_retire) + total_annual * (pow(1 + r, years_to_retire) - 1) / r

Total Contributions

total_contributions = total_annual * years_to_retire

Investment Growth

total_growth = future_value - current_balance - total_contributions

Total Employer Match

employer_total = employer_contribution * years_to_retire

Variables

VariableDescriptionDefault
current_balanceCurrent Balance(USD)50000
annual_contributionAnnual Contribution(USD)19500
employer_match_pctEmployer Match(%)50
match_limit_pctMatch Limit (% of Salary)(%)6
salaryAnnual Salary(USD)85000
annual_returnExpected Annual Return(%)7
years_to_retireYears Until Retirement(years)25
rDerived value= annual_return / 100calculated
employer_contributionDerived value= salary * match_limit_pct / 100 * employer_match_pct / 100calculated
total_annualDerived value= annual_contribution + employer_contributioncalculated

How It Works

How the 401(k) Calculator Works

This calculator projects your retirement savings using compound growth on both your existing balance and future contributions.

Formula

FV = PV × (1 + r)^n + PMT × [(1 + r)^n − 1] / r

Where:

  • PV = Current balance
  • PMT = Annual contribution + employer match
  • r = Annual rate of return
  • n = Years until retirement
  • Employer match is calculated as: Salary × Match Limit % × Match Rate %.

    Worked Example

    $50,000 current balance, $19,500/yr contribution, 50% employer match up to 6% of an $85,000 salary, 7% return, 25 years.

    current_balance = 50000annual_contribution = 19500employer_match_pct = 50match_limit_pct = 6salary = 85000annual_return = 7years_to_retire = 25
    1. 01Employer match = $85,000 × 6% × 50% = $2,550/yr
    2. 02Total annual = $19,500 + $2,550 = $22,050
    3. 03Current balance growth = $50,000 × (1.07)^25 = $271,372
    4. 04Contribution growth = $22,050 × [(1.07)^25 − 1] / 0.07 = $1,393,751
    5. 05Projected balance = $271,372 + $1,393,751 = $1,665,123

    Ready to run the numbers?

    Open 401(k) Calculator