Skip to main content
CodeLint.Dev Dev Tools
FinTech 10 min read

Compound Interest: The Complete Guide to the Formula, Frequency, and the Rule of 72

Albert Einstein supposedly called compound interest the "eighth wonder of the world." Whether or not he said it, the math backs up the hyperbole: a single initial investment can grow to 10× its value purely through compounding — with no additional contributions — given enough time. This guide covers the exact formula behind compound interest, how compounding frequency affects your returns, the mental math shortcut every investor should know, code examples in Python and JavaScript, and the common calculation mistakes that lead to incorrect projections.

Try the tool
Compound Interest Calculator
Calculate compound growth free →

Simple Interest vs Compound Interest: The Fundamental Difference

Simple interest calculates interest only on the original principal. Compound interest calculates interest on both the principal and all previously earned interest. This distinction seems minor for short time periods but produces dramatically different outcomes over decades.

Year Simple Interest (10%) Compound Interest (10%)
0$10,000$10,000
5$15,000$16,105
10$20,000$25,937
20$30,000$67,275
30$40,000$174,494

Starting from $10,000 at 10% annual interest: after 30 years, simple interest yields $40,000. Compound interest yields $174,494 — more than four times as much. The extra $134,000 is earned entirely by interest accruing on interest.

This is why financial advisers emphasise starting early: an extra 10 years at the beginning of a compounding curve is worth far more than an extra 10 years at the end.

The Compound Interest Formula

The standard compound interest formula is:

A = P × (1 + r/n)^(n×t)

Where:

  • A — final amount (principal + interest)
  • P — principal (initial investment)
  • r — annual interest rate as a decimal (e.g. 7% = 0.07)
  • n — number of times interest is compounded per year
  • t — time in years

Example: $5,000 invested at 6% annual interest, compounded monthly, for 10 years:

A = 5000 × (1 + 0.06/12)^(12×10)
A = 5000 × (1.005)^120
A = 5000 × 1.8194
A = $9,096.98

The total interest earned is $9,096.98 − $5,000 = $4,096.98 — nearly doubling the original investment without a single additional contribution.

For continuous compounding (the mathematical limit as n → ∞), the formula simplifies to:

A = P × e^(r×t)

Continuous compounding is used in certain financial derivatives and theoretical models; real-world savings accounts and investments use discrete compounding (daily, monthly, or annually).

Compounding Frequency: How Often Matters

The variable n — the number of compounding periods per year — has a real but often overestimated effect on final returns. More frequent compounding is always better for an investor, but the difference between monthly and daily compounding is small. The difference between annual and monthly compounding is more meaningful.

Frequency n $10,000 at 8% for 20 years
Annually1$46,609.57
Quarterly4$48,010.21
Monthly12$48,454.49
Daily365$49,020.00
Continuous$49,021.28

Going from annual to monthly compounding on a $10,000 investment over 20 years gains you ~$1,845. Going from monthly to daily gains you only another ~$565. Time in the market matters far more than compounding frequency.

For credit card debt and loans, the logic is inverted — more frequent compounding hurts the borrower. A credit card with 24% APR compounded daily has an effective annual rate (EAR) of (1 + 0.24/365)^365 − 1 = 27.11%, significantly higher than the advertised 24%.

The Rule of 72: Mental Math Shortcut

The Rule of 72 lets you estimate the doubling time of an investment without a calculator:

Years to double ≈ 72 / annual interest rate (%)

Examples:

  • At 6%: 72 / 6 = 12 years to double
  • At 8%: 72 / 8 = 9 years to double
  • At 12%: 72 / 12 = 6 years to double
  • At 1% (savings account): 72 / 1 = 72 years to double

The Rule of 72 is an approximation — it is most accurate for rates between 6% and 10%. For higher rates, use the Rule of 70 or the Rule of 69.3 (which is exact for continuous compounding).

You can also use it in reverse: if you want your money to double in 10 years, you need an annual return of 72/10 = 7.2%.

And for inflation: if inflation runs at 3%, purchasing power halves in 72/3 = 24 years. A dollar today buys 50 cents' worth of goods in 2049 at 3% inflation.

Code Examples: Compound Interest in Python and JavaScript

These implementations handle the general compound interest formula and generate a year-by-year amortization schedule.

Python Python
def compound_interest(principal, rate, n, years):
    """
    principal: initial amount
    rate: annual rate as decimal (e.g. 0.07 for 7%)
    n: compounding periods per year (12 = monthly)
    years: investment duration
    """
    amount = principal * (1 + rate / n) ** (n * years)
    interest = amount - principal
    return round(amount, 2), round(interest, 2)

def amortization_table(principal, rate, n, years):
    """Generates year-by-year growth table."""
    rows = []
    for year in range(1, years + 1):
        amount, interest = compound_interest(principal, rate, n, year)
        rows.append({
            'year': year,
            'balance': amount,
            'interest_earned': interest,
        })
    return rows

# Example: $10,000 at 7% compounded monthly for 20 years
amount, interest = compound_interest(10_000, 0.07, 12, 20)
print(f"Final amount: ${amount:,.2f}")
print(f"Total interest: ${interest:,.2f}")

table = amortization_table(10_000, 0.07, 12, 20)
for row in table[::5]:  # print every 5th year
    print(f"Year {row['year']:2d}: ${row['balance']:>12,.2f}")
JavaScript JavaScript
/**
 * Calculates compound interest.
 * @param {number} principal - Initial amount
 * @param {number} rate - Annual rate as decimal (0.07 = 7%)
 * @param {number} n - Compounding periods per year
 * @param {number} years - Duration in years
 */
function compoundInterest(principal, rate, n, years) {
  const amount = principal * Math.pow(1 + rate / n, n * years);
  return {
    amount: Math.round(amount * 100) / 100,
    interest: Math.round((amount - principal) * 100) / 100,
  };
}

function ruleOf72(rate) {
  return 72 / (rate * 100);  // rate as decimal
}

// Year-by-year schedule
function amortizationSchedule(principal, rate, n, years) {
  return Array.from({ length: years }, (_, i) => {
    const { amount, interest } = compoundInterest(principal, rate, n, i + 1);
    return { year: i + 1, balance: amount, interestEarned: interest };
  });
}

// Example
const { amount, interest } = compoundInterest(10_000, 0.07, 12, 20);
console.log(`Final: $${amount.toLocaleString()}`);
console.log(`Interest: $${interest.toLocaleString()}`);
console.log(`Rule of 72 (7%): doubles in ~${ruleOf72(0.07).toFixed(1)} years`);

Common Compound Interest Calculation Mistakes

  1. Using the rate as a percentage instead of a decimal. Plugging 7 instead of 0.07 into the formula produces wildly wrong results. Always convert: rate% ÷ 100 = rate decimal.
  2. Confusing APR and APY. APR (Annual Percentage Rate) does not account for compounding within the year. APY (Annual Percentage Yield) does. When comparing savings accounts or loans, always compare APY — it is the true effective annual rate. A 12% APR compounded monthly equals a 12.68% APY.
  3. Ignoring inflation. A 7% nominal return in a 3% inflation environment is a real return of approximately 3.88% (not simply 4%). Use the Fisher equation for real returns: real rate = (1 + nominal) / (1 + inflation) − 1.
  4. Assuming taxes away. Investment gains are typically taxable events. A 7% gross return becomes 5.6% net in a 20% capital gains tax environment. Tax-advantaged accounts (401k, IRA, ISA, ELSS) change this calculation significantly.
  5. Forgetting fees. A 1% annual management fee on a fund compounding at 8% will consume roughly 12.5% of your 20-year return. (1.08/1.01)^20 = 3.87× vs (1.08)^20 = 4.66× — the fee eats $0.79 of every $4.66 earned.

Frequently Asked Questions

What is the difference between APR and APY?
APR (Annual Percentage Rate) is the interest rate without accounting for the effect of compounding within the year. APY (Annual Percentage Yield) reflects the actual return after intra-year compounding is accounted for. For a 12% APR compounded monthly, the APY is (1 + 0.12/12)^12 − 1 = 12.68%. When comparing financial products, always compare APYs — banks are required by law to disclose APY in most countries.
Does compounding frequency really matter that much?
The difference between annual and monthly compounding is meaningful — on a $10,000 investment at 8% over 20 years, monthly compounding earns ~$1,845 more than annual. However, the difference between monthly and daily compounding is only ~$565 over the same period. Beyond monthly, the gains from more frequent compounding are marginal. Far more important factors are the interest rate itself, the investment duration, and whether you make regular contributions.
What is the Rule of 72 and how accurate is it?
The Rule of 72 estimates the doubling time of an investment: divide 72 by the annual interest rate percentage to get the approximate years to double. It is most accurate for rates between 6% and 10%. For lower rates, the Rule of 70 is slightly more accurate. For continuous compounding, the mathematically exact divisor is 69.3 (= 100 × ln(2)). The Rule of 72 is a mental arithmetic shortcut, not an exact calculation.
How do I calculate compound interest with regular contributions?
Adding regular contributions (a savings/investment plan) requires a separate formula. For a regular contribution C per period: FV = P × (1 + r/n)^(n×t) + C × [((1 + r/n)^(n×t) − 1) / (r/n)]. This is the future value of an annuity added to the compounded principal. The CodeLint.Dev Compound Interest Calculator handles both lump sum and regular contribution scenarios.
What is continuous compounding and when is it used?
Continuous compounding is the mathematical limit of increasing compounding frequency infinitely. The formula is A = P × e^(r×t), where e is Euler's number (~2.71828). Continuous compounding is used in theoretical finance, options pricing (Black-Scholes model), and some interest rate models. Real-world financial products always use discrete compounding (daily, monthly, quarterly, or annually).
How does compound interest work against you in debt?
The same compounding that grows investments also grows debt. Credit card balances at 24% APR compounded daily have an effective annual rate of 27.11%. If you carry a $5,000 balance for 3 years without payments, compound interest grows the debt to $10,566 — more than double. The fastest way to destroy compound interest's positive effect is to carry high-interest debt. Pay off high-APR debt first (avalanche method) before investing in low-return savings.

Ready to try Compound Interest Calculator?

Free, private, and runs entirely in your browser — no sign-up, no server, no data sent anywhere.

Open Compound Interest Calculator