DEV Community

Cover image for I built a FIRE calculator in a single HTML file. Here's the math.
lsj
lsj

Posted on

I built a FIRE calculator in a single HTML file. Here's the math.

Every FIRE calculator I found wanted my email. Or showed ads. Or tried to sell me a "personalized retirement plan" for $29/month.

I just wanted the math.

So I built one. Single HTML file, zero dependencies, 32KB. Open source on GitHub, MIT license. Try it here.

The two formulas that matter

FIRE Number = Annual Spending / Safe Withdrawal Rate
Coast FIRE Number = FIRE Number / (1 + Real Return Rate)^Years to Retirement
Enter fullscreen mode Exit fullscreen mode

That's it. The Trinity Study (1998) says you can safely withdraw 4% per year in retirement. The S&P 500 has returned ~10% nominally since 1926, inflation eats ~3%, so real return is ~7%.

Run the numbers for a 30-year-old who spends $40K/year and wants to retire at 65:

  • FIRE Number: $40,000 / 0.04 = $1,000,000
  • Coast FIRE Number: $1,000,000 / (1.07)^35 = $93,676

Ninety-four thousand dollars. If you're 30 and have that much invested right now, you never need to save another dollar. Compound interest does the rest over 35 years.

That number gets bigger the longer you wait. At 40, it's $244K. At 50, it's $453K. Time is the variable that costs the most when you waste it.

Why zero dependencies

I wanted the calculator to be embeddable. Blogs, personal finance sites, forums — anyone should be able to drop it in with an iframe or just download the HTML file.

<iframe src="https://coastfirehub.com/embed/coast-fire-calculator.html"
        width="100%" height="600"
        style="border:1px solid #E2E8F0;border-radius:12px;">
</iframe>
Enter fullscreen mode Exit fullscreen mode

That meant no build step, no npm, no framework. Vanilla JS with inline styles. The code isn't pretty. But it loads fast and runs anywhere.

No CDN calls. No analytics. No tracking. Your financial data stays in your browser.

From one file to a full app

The single HTML file is still maintained as an open source repo. But it also grew into CoastFIRE Hub — a Next.js app with 5 calculator types (Coast, Barista, Fat, Lean, and a Grid lookup by age), projection charts, URL parameter sharing, and a Chrome extension.

The math stays in one file (lib/calculations.ts) and gets synced across the web app, the standalone HTML, and the Chrome extension. One source of truth.

One thing I didn't expect: open-sourcing the calculator logic did more for user trust than any feature. People running their retirement numbers want to see the formula first. Reasonable.


Top comments (0)