My smartwatch told me I burned 3,400 calories yesterday. My partner's app told me I burned 2,200. Both are wrong, in different directions, and I am tired of trusting black boxes that disagree. So I sat down with the formulas a sports scientist would actually use and built a tiny CLI for myself.
This post is the boring, deterministic version of fitness math. No heart rate sensors, no proprietary algorithms, just the same equations dietitians have used for decades. The TypeScript is short on purpose; the value is in seeing the formulas written next to each other.
BMI: not a fitness number, but a useful baseline
First, the dumbest one. BMI is a quick way to flag whether someone is in a healthy weight range, no more.
function bmi(weightKg: number, heightCm: number): number {
const heightM = heightCm / 100;
return weightKg / (heightM * heightM);
}
bmi(82, 178); // 25.88
It does not know about muscle versus fat, which is why bodybuilders show up as "obese" on a BMI chart. But if you are not a bodybuilder, it correlates surprisingly well with health outcomes at the population level.
When a friend asks me for the categories (under, normal, over, obese class I/II/III), I send them to the BMI Calculator on Equation Solver, which renders the WHO bands next to the number so they can place themselves without me reciting cutoffs.
BMR: the metabolic floor
Basal Metabolic Rate is what your body burns at rest. The Mifflin-St Jeor equation is the modern standard:
function bmr({
weightKg,
heightCm,
age,
sex,
}: {
weightKg: number;
heightCm: number;
age: number;
sex: "male" | "female";
}): number {
const base = 10 * weightKg + 6.25 * heightCm - 5 * age;
return sex === "male" ? base + 5 : base - 161;
}
bmr({ weightKg: 82, heightCm: 178, age: 35, sex: "male" }); // 1747.5
That 1,747 is the number of calories my body would burn if I lay perfectly still all day. It is the floor my smartwatch's number should never go below, and yet on rest days mine sometimes claims it did. Reality check, please.
For the side-by-side comparison with the older Harris-Benedict formula, the BMR Calculator on Equation Solver shows both, which is genuinely useful when you are reading older diet books that quote one and not the other.
TDEE: BMR with movement
Total Daily Energy Expenditure scales BMR by an activity factor:
const activityFactors = {
sedentary: 1.2,
light: 1.375,
moderate: 1.55,
active: 1.725,
veryActive: 1.9,
} as const;
function tdee(bmrValue: number, level: keyof typeof activityFactors): number {
return bmrValue * activityFactors[level];
}
tdee(1747.5, "moderate"); // 2708.6
This is the calorie target diet apps quote you. Eat at it to maintain, eat under it to lose, eat over to gain. Unlike my smartwatch, this number does not fluctuate by 1,200 calories a day depending on whether I forgot to start the workout timer.
If you want to play with the activity factors visually, the TDEE Calculator on Equation Solver lays them out as a dropdown, and shows you how the choice affects your maintenance calories in real time. Useful for the conversation "am I really sedentary or am I lying to myself?"
Body fat percentage from a tape measure
The US Navy formula is the closest you can get to a body fat estimate without a scale that lies to you. For men:
function navyBodyFatMale({
waistCm,
neckCm,
heightCm,
}: {
waistCm: number;
neckCm: number;
heightCm: number;
}): number {
return (
495 /
(1.0324 -
0.19077 * Math.log10(waistCm - neckCm) +
0.15456 * Math.log10(heightCm)) -
450
);
}
navyBodyFatMale({ waistCm: 92, neckCm: 39, heightCm: 178 }); // ~21.3
It is not lab-grade, but it is consistent week to week with a tape, and that consistency is what you actually want when tracking change. The Body Fat Calculator on Equation Solver covers the female version and explains the measurement points, which matters more than the formula; sloppy measurements are the main source of error here.
Putting it together
With those four functions you have everything you need to argue back at a smartwatch. Mine now lives in a fitness.ts file with a tiny CLI wrapper around it. When the watch tells me I burned 3,400 calories on a couch day, I check against TDEE, see that the ceiling is 2,700 even with optimistic assumptions, and ignore the watch with a clean conscience.
The broader lesson, for me at least: when an app makes a confident-sounding claim about your body, it usually rests on one of these formulas anyway. Knowing the math turns mystery into engineering, and engineering is something we can argue with.
Top comments (0)