The math
There isn't a real equation here, and pretending otherwise would be the dishonest move. Detection windows come from published clinical ranges, not from a formula you can derive. What this page does is pick the right published range for your pattern of use and lay it against your last-use time.
window = published range for [substance][frequency]
adjusted = window × body-mass factor (cannabis only)
window ends = last use + upper bound
Your weight and height are asked for, and then deliberately not used to change anything. That needs explaining. THC really does store in fat, so it's reasonable to expect a heavier person to test positive for longer, and an earlier version of this page multiplied the cannabis windows by a BMI factor on exactly that reasoning. The number behind it was invented rather than measured, and when we went looking for something to justify it we found the opposite. Schuster and colleagues tracked 62 cannabis users through a month of verified abstinence and reported that sex, BMI, race, years of use and past-month frequency were all not significantly associated with how fast THC-COOH cleared. So the factor is gone, the windows are exactly what the sources say, and the readout shows your BMI with no adjustment attached to it.
Frequently asked
Why is the marijuana window so much longer than everything else?
Because THC is fat-soluble and almost nothing else on this page is. Cocaine, meth, heroin and opioid pills are cleared through water-based routes within days. THC parks itself in fatty tissue and leaches back out slowly, so the metabolite that urine tests look for keeps appearing long after the effects are gone. That's also why frequency matters so much more for cannabis - each session tops the store back up. A first-time user is usually clear in a few days, while someone smoking several times a day can still test positive a month later.
Does drinking water or exercising shorten the window?
Not meaningfully, and both can backfire. Drinking a lot of water dilutes your urine rather than removing anything, and labs test for that directly - a sample with low creatinine and low specific gravity is flagged as dilute, which is usually treated as a failed or invalid test rather than a pass. Exercise mobilises fat and can briefly raise the THC metabolite in your blood and urine, so training hard the day before a test can push a borderline result the wrong way. Nothing on the market reliably speeds elimination up.
How far back does a hair test really go?
Two of our sources give the same answer on the front of that window - use does not show until it has grown 7 to 10 days out of the scalp, so a hair test is close to blind to the past week and a half. On the back of it they spread: three put the window at roughly 90 days and SAMHSA TIP 47 puts it at four to six months, which averages to about 105 days. Hair is also poor at catching one-off use, since it detects patterns rather than single occasions. And it is worth knowing that hair is not an approved specimen for federally regulated workplace testing at all.
Will this tell me whether I'll pass a specific test?
No, and no calculator can. These are population ranges drawn from published detection windows, and individual variation is enormous - metabolism, kidney and liver function, dose and potency, how it was taken, hydration, body composition and other medications all move the number. The test itself matters too, because the cutoff differs between panels and a lab confirmation test is far more sensitive than the initial screen. Treat the output as a rough sense of scale rather than a date to plan around.