<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: aadifit</title>
    <description>The latest articles on DEV Community by aadifit (@aadifit).</description>
    <link>https://dev.to/aadifit</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4137571%2F815cccc2-e805-4a71-ae4e-1f0e256ee6e6.png</url>
      <title>DEV Community: aadifit</title>
      <link>https://dev.to/aadifit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aadifit"/>
    <language>en</language>
    <item>
      <title>Building an open-source TDEE calculator you can actually verify</title>
      <dc:creator>aadifit</dc:creator>
      <pubDate>Tue, 22 Sep 2026 13:01:08 +0000</pubDate>
      <link>https://dev.to/aadifit/building-an-open-source-tdee-calculator-you-can-actually-verify-4g0e</link>
      <guid>https://dev.to/aadifit/building-an-open-source-tdee-calculator-you-can-actually-verify-4g0e</guid>
      <description>&lt;p&gt;Every TDEE (Total Daily Energy Expenditure) calculator I found online was the same thing: a form behind a wall of ads, math you can't see, and no way to reuse it in your own project. So I pulled the formulas out into a small, tested, MIT-licensed package and a zero-permission browser extension.&lt;/p&gt;

&lt;h2&gt;
  
  
  The formulas
&lt;/h2&gt;

&lt;p&gt;TDEE calculators are built from two numbers:&lt;br&gt;
&lt;strong&gt;BMR (Basal Metabolic Rate)&lt;/strong&gt; — calories your body burns at rest.&lt;br&gt;
An activity multiplier — how much more you burn based on how active&lt;br&gt;
you are (1.2x for sedentary, up to 1.9x for very active).&lt;br&gt;
&lt;code&gt;TDEE = BMR x activity multiplier&lt;/code&gt;&lt;br&gt;
The part everyone gets subtly wrong is BMR. There are three formulas in&lt;br&gt;
actual use, and they disagree with each other on purpose:&lt;br&gt;
&lt;strong&gt;Mifflin-St Jeor (1990)&lt;/strong&gt; — the default in most modern tools, and the most&lt;br&gt;
accurate across the general population according to a 2005 validation study&lt;br&gt;
in the Journal of the American Dietetic Association that compared it&lt;br&gt;
against several older formulas:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;male:   10 x weight(kg) + 6.25 x height(cm) - 5 x age + 5
female: 10 x weight(kg) + 6.25 x height(cm) - 5 x age - 161
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Katch-McArdle&lt;/strong&gt; — uses lean body mass instead of total weight, so it's&lt;br&gt;
more accurate if you actually know your body fat percentage (DEXA scan,&lt;br&gt;
reliable calipers — not the scale-with-electrodes kind):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BMR = 370 + 21.6 x lean_mass_kg
lean_mass_kg = weight_kg x (1 - body_fat_pct / 100)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Harris-Benedict (1984 revision)&lt;/strong&gt; — the older standard, included mostly&lt;br&gt;
for compatibility with tools that still use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;male:   13.397 x weight(kg) + 4.799 x height(cm) - 5.677 x age + 88.362
female: 9.247 x weight(kg) + 3.098 x height(cm) - 4.330 x age + 447.593
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a 30-year-old, 80kg, 180cm male, these three give 1780, ~1839 (at 15%&lt;br&gt;
body fat), and ~1854 kcal respectively — a real 70+ kcal spread just from&lt;br&gt;
formula choice, before you even touch activity level.&lt;/p&gt;
&lt;h2&gt;
  
  
  Macros
&lt;/h2&gt;

&lt;p&gt;Once you have TDEE, splitting it into protein/carb/fat grams is a second&lt;br&gt;
formula most calculators bolt on badly. I used a fixed-fat-percentage&lt;br&gt;
approach — protein and fat needs scale with body weight and hormones, carbs&lt;br&gt;
are the flexible lever:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;targetKcal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tdee&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;goalAdjustment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// cut: -20%, bulk: +10%&lt;/span&gt;
&lt;span class="nx"&gt;proteinG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;proteinPerKg&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;weightKg&lt;/span&gt;          &lt;span class="c1"&gt;// cut: 2.2, maintain: 2.0, bulk: 1.8&lt;/span&gt;
&lt;span class="nx"&gt;fatG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetKcal&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;fatPct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;            &lt;span class="c1"&gt;// 25-28% of calories&lt;/span&gt;
&lt;span class="nx"&gt;carbG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetKcal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;proteinKcal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;fatKcal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;   &lt;span class="c1"&gt;// whatever's left&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The package
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/@aadifit/tdee-calc" rel="noopener noreferrer"&gt;@aadifit/tdee-calc&lt;/a&gt; - zero dependencies, ~150 lines, MIT licensed, every formula checked against&lt;br&gt;
hand-derived reference values in the test suite (16 tests):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @aadifit/tdee-calc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;```js const { mifflinStJeor, tdee, macroSplit } = require('&lt;a href="https://www.npmjs.com/package/@aadifit/tdee-calc" rel="noopener noreferrer"&gt;@aadifit/tdee-calc&lt;/a&gt;');&lt;/p&gt;

&lt;p&gt;const bmr = mifflinStJeor({ weightKg: 80, heightCm: 180, age: 30, sex: 'male' });&lt;br&gt;
// 1780&lt;/p&gt;

&lt;p&gt;const maintenance = tdee(bmr, 'moderate');&lt;br&gt;
// 2759&lt;/p&gt;

&lt;p&gt;const macros = macroSplit(maintenance, { weightKg: 80, goal: 'maintain' });&lt;br&gt;
// { targetKcal: 2759, proteinG: 160, fatG: 86, carbG: 336 }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Source: [github.com/aadifit/tdee-calc](github.com/aadifit/tdee-calc)

## The extension
Same formulas, wrapped in a [Firefox extension](addons.mozilla.org/en-US/firefox/addon/tdee-macro-calculator/) that's just a popup — no permissions, no network requests, no data
collection. If you're curious what a genuinely zero-permission
`manifest.json` looks like:


```json
{
  "manifest_version": 3,
  "action": { "default_popup": "popup.html" },
  "permissions": [],
  "browser_specific_settings": {
    "gecko": {
      "data_collection_permissions": { "required": ["none"] }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Source: &lt;a href="//github.com/aadifit/tdee-extension"&gt;github.com/aadifit/tdee-extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;

&lt;p&gt;I maintain &lt;a href="https://aadifit.com" rel="noopener noreferrer"&gt;AadiFit&lt;/a&gt;, an AI coaching platform, and&lt;br&gt;
wanted the calculation layer to be something people could actually check&lt;br&gt;
instead of trusting a black box. If you want the full version — body&lt;br&gt;
composition tracking, activity logging, an adaptive plan built around your&lt;br&gt;
actual numbers instead of a static calculator — that's at&lt;br&gt;
&lt;a href="https://aadifit.com/tdee-calculator" rel="noopener noreferrer"&gt;aadifit.com/tdee-calculator&lt;/a&gt;. But the math itself is free, open, and yours to use however you want.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>opensource</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
