I Built a BAC Calculator in Vanilla JS - and Fell Into the Widmark Formula Rabbit Hole
Same three drinks, same body weight, one hour later. He estimates under the 0.08 limit. She estimates over it. Nobody drank more. Nobody weighs more. The entire difference is one constant in a formula written in 1932 -
Same three drinks, same body weight, one hour later. He estimates under the 0.08 limit. She estimates over it.
Nobody drank more. Nobody weighs more. The entire difference is one constant in a formula written in 1932 - and until I built this tool, I had no idea it existed.
So I built a free BAC calculator for CalcVersa that estimates blood alcohol content from drinks, body weight and time. No framework, no backend - one HTML file with vanilla JS that runs entirely in the browser. Here's the part that surprised me.
Step one: turn drinks into grams
The formula doesn't speak in beers or glasses. It speaks in grams of pure alcohol, and the bridge is the standard drink:
| Drink | Typical serving | Pure alcohol |
|---|---|---|
| Beer (5%) | 355 ml | โ 14 g |
| Wine (12%) | 148 ml | โ 14 g |
| Shot (40%) | 44 ml | โ 14 g |
Three drinks of anything โ 42 grams. Already, this is the first lie the math tells - a generous restaurant pour of wine can quietly be a drink and a half - but hold that thought.
The formula: one division, one subtraction
The Widmark formula, from Swedish chemist Erik Widmark:
BAC = A รท (W ร r) โ 0.015 ร t
- A - alcohol consumed, in grams
- W - body weight, in grams
- r - the distribution factor: 0.68 for men, 0.55 for women
- 0.015 ร t - elimination: the body burns off alcohol at roughly 0.015 per hour, and nothing speeds that up. Not coffee, not a cold shower, not willpower.
The r factor is the whole story of the opening example. Alcohol dissolves in body water, not fat - and men carry proportionally more body water than women. Same alcohol, less water to dilute it, higher concentration. In code, the entire calculator core is this:
var R = { male: 0.68, female: 0.55 }; // Widmark distribution factor
var ELIMINATION = 0.015; // per hour, roughly constant
function estimateBAC(drinks, weightKg, sex, hours) {
var grams = drinks * 14; // 1 standard drink โ 14 g
var peak = grams / (weightKg * 1000 * R[sex]) * 100;
var bac = peak - ELIMINATION * hours;
return Math.max(0, bac);
}
Check it against the hook: 70 kg, 3 drinks. Man: 42 รท (70,000 ร 0.68) ร 100 = 0.088, minus an hour of elimination = 0.073. Woman: 42 รท (70,000 ร 0.55) ร 100 = 0.109, minus the hour = 0.094. The formula reproduces the puzzle exactly.
And because elimination is linear, the two questions users actually care about - when am I at zero? and when am I under 0.08? - are the same one-line function:
function hoursTo(bac, target) {
return bac > target ? (bac - target) / ELIMINATION : 0;
}
The decision I actually had to make
The code took an afternoon. Deciding how exact to pretend to be took longer.
Because every input to that formula is an average wearing a lab coat. The elimination rate of 0.015 is a population average - real bodies range from about 0.010 to 0.025. The formula assumes the alcohol is absorbed instantly, when a real peak arrives 30 to 90 minutes after the last drink, later still on a full stomach. Even r shifts with individual body composition.
So the tool shows status bands, not false precision - a range of "where you roughly are", the estimated time to zero, and the estimated time under 0.08, all labelled as estimates. And one hard rule I wouldn't bend: the page never, anywhere, says "safe to drive". It shows numbers and a disclaimer that this is an educational estimate, not a measurement. A breathalyser measures. A formula guesses - an educated guess, but a guess.
What I deliberately kept boring
- No framework. The whole tool is one self-contained block, so it can be pasted into any page builder and just work.
- Estimates labelled as estimates. No green "you're fine" verdict anywhere - the tool reports a number and its limits, and the driving decision stays with the human.
- Everything client-side. Nothing typed into the calculator ever leaves the browser - which matters double here, because nobody wants their drinking data sent to a server.
Try it
The calculator is live here: BAC Calculator - it sits next to its sibling health tools, a BMI calculator and a calorie calculator, and handles kg/lb switching, beer/wine/shot presets, and both time estimates.
If you build tools that estimate things about a person's body: how do you show a number without pretending it's exact?
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.