The Math Behind Compound Interest — And Why It Matters More Than You Think

Compound interest is one of those concepts that's easy to describe but hard to intuitively grasp. Let's build a calculator and explore what the numbers actually show.

The Formula

A = P(1 + r/n)^(nt) 

Where:

  • A = final amount
  • P = principal
  • r = annual interest rate (decimal)
  • n = compounding periods per year
  • t = years
function compound(principal, annualRate, years, periodsPerYear = 12) { const r = annualRate / 100; const n = periodsPerYear; return principal * Math.pow(1 + r / n, n * years); } 

Adding Monthly Contributions

Most real-world scenarios involve regular contributions. The formula becomes:

A = P(1 + r/n)^(nt) + PMT × ((1 + r/n)^(nt) - 1) / (r/n) 
function compoundWithContributions(principal, annualRate, years, monthlyContribution, periodsPerYear = 12) { const r = annualRate / 100; const n = periodsPerYear; const nt = n * years; const rn = r / n; const principalGrowth = principal * Math.pow(1 + rn, nt); const contributionGrowth = monthlyContribution * (Math.pow(1 + rn, nt) - 1) / rn; return principalGrowth + contributionGrowth; } 

Generating a Year-by-Year Table

function generateYearlyBreakdown(principal, annualRate, years, monthlyContribution) { const rows = []; let balance = principal; const monthlyRate = annualRate / 100 / 12; let totalContributions = principal; for (let year = 1; year <= years; year++) { for (let month = 0; month < 12; month++) { balance = balance * (1 + monthlyRate) + monthlyContribution; totalContributions += monthlyContribution; } rows.push({ year, balance: Math.round(balance), totalContributions: Math.round(totalContributions), totalInterest: Math.round(balance - totalContributions), }); } return rows; } 

The Rule of 72

A quick mental math trick: divide 72 by the annual interest rate to estimate how many years until your money doubles.

function yearsToDouble(annualRate) { return 72 / annualRate; } // 8% rate → ~9 years to double 

Compounding Frequency Matters Less Than You Think

Daily vs. monthly compounding has a surprisingly small effect:

Frequency $10,000 at 10% for 10 years
Annual $25,937
Monthly $27,070
Daily $27,179

The difference between monthly and daily is only $109 over 10 years.

Explore compound interest at toolzip.app/tools/compound-calculator.