Bayes' Theorem Calculator
Update a probability once new evidence arrives — interpret a diagnostic test result, compare several competing hypotheses at once, or chain multiple pieces of evidence together — each with its own visual, full step-by-step math, and a callout explaining what the number actually means.
Background
Bayes' theorem tells you how to update a "prior" belief into a "posterior" belief once you observe evidence. It's the mathematical backbone of medical testing, spam filters, forensic reasoning, and machine learning classifiers — anywhere you need to ask "given what I just observed, how likely is each explanation now?"
How to use this calculator
- Choose Diagnostic Test to interpret a positive or negative test result given a condition's prevalence, sensitivity, and specificity.
- Choose Multiple Hypotheses to see which of up to three competing explanations best accounts for a single piece of evidence.
- Choose Sequential Updating to chain two or three pieces of evidence together, watching the probability evolve one test at a time.
- Click Calculate to see the visual, the full step-by-step math, and a callout explaining what the result means.
How Bayes' Theorem Works
Bayes' theorem converts a "prior" belief into a "posterior" belief once evidence arrives: P(A|B) = P(B|A)·P(A) / P(B). It's just a formal rule for updating your mind.
The denominator P(B) is the total probability of the evidence, added up across every possible hypothesis, weighted by how likely each one made that evidence.
A hypothesis's posterior depends on two things: how likely it was before the evidence (its prior) and how well it predicted the evidence (its likelihood). A strong prior can still lose the lead if it predicts the evidence poorly.
With exactly two possibilities — a condition and its absence — Bayes' theorem is usually phrased with sensitivity (true positive rate) and specificity (true negative rate). This is exactly how doctors interpret test results.
With more than two hypotheses, the same formula is applied to each one, then every result is divided by the combined total so the posteriors add up to 100%.
Applying Bayes' theorem more than once — using yesterday's posterior as today's prior — is called sequential updating. It's mathematically identical to folding all the evidence into one big calculation, and both are governed by the same shortcut: each new test multiplies the running odds by its own likelihood ratio.
Formulas & Equations Used
General form: P(A|B) = P(B|A)·P(A) / P(B)
Two-hypothesis (diagnostic) form: P(A|B) = P(B|A)·P(A) / [P(B|A)·P(A) + P(B|¬A)·P(¬A)]
Multiple hypotheses: P(Hⁱ|E) = P(E|Hⁱ)·P(Hⁱ) / Σₖ P(E|Hₖ)·P(Hₖ)
Odds form (likelihood ratio): posterior odds = prior odds × LR, where LR+ = sensitivity / (1 − specificity) and LR− = (1 − sensitivity) / specificity
Sequential updating: posteriorₙ becomes priorₙ₊₁ for the next piece of evidence; equivalently, the running odds are multiplied by each test's own LR in turn
Example Problems & Step-by-Step Solutions
Example 1 — The rare-disease paradox
A disease affects 1% of people. A test is 99% sensitive and 99% specific. A random person tests positive.
Step: P(+) = 0.99×0.01 + 0.01×0.99 = 0.0198. P(disease|+) = 0.0099 / 0.0198.
Result: Only 50% — despite the test's 99% accuracy.
Example 2 — Three competing hypotheses
Three factories share production 70% / 20% / 10%, with defect rates 5% / 30% / 95%. A defective part is found.
Step: Weights = 0.035, 0.06, 0.095 (sum 0.19). Divide each by 0.19.
Result: The smallest factory (10% share) is now the most likely source, at 50%.
Example 3 — Testing twice
Same 1% disease, 99%/99% test, but the person is tested twice, both times positive.
Step: After test 1, the posterior (50%) becomes the new prior for test 2. Equivalently, the odds get multiplied by the test's likelihood ratio (99) twice.
Result: After the second positive test, the probability jumps to about 99%.
Example 4 — The witness problem
85% of cabs in a city are green, 15% are blue. A witness who is 80% reliable at telling colors apart says the cab was blue.
Step: P(says blue) = 0.8×0.15 + 0.2×0.85 = 0.29. P(blue|says blue) = 0.12 / 0.29.
Result: Only about 41% — well below most people's intuitive guess.
Frequently Asked Questions
What's the difference between prior and posterior probability?
The prior is what you believed before seeing the evidence. The posterior is the updated belief after Bayes' theorem folds that evidence in. The posterior from one update can become the prior for the next.
Why does a rare condition make even accurate tests unreliable?
When the condition is rare, the huge pool of healthy people produces more false positives in absolute terms than the tiny pool of sick people produces true positives — even at a low false-positive rate. This is often called the false-positive paradox.
Do the hypotheses' priors need to add up to 100%?
They should represent a complete, mutually exclusive set of possibilities, so yes — but this calculator rescales them proportionally if they don't, so small rounding differences in your inputs won't throw off the result.
Is testing twice the same as combining the evidence at once?
Yes, as long as the tests are independent given the true state. Feeding one test's posterior in as the next test's prior produces exactly the same final answer as multiplying both likelihoods together in a single calculation — or, equivalently, multiplying both tests' likelihood ratios into the starting odds.
What if the evidence seems impossible under every hypothesis?
Then the denominator of Bayes' theorem is 0 and the posterior is undefined — this calculator flags that instead of showing a meaningless number. In practice it usually means one of the input probabilities was mis-entered.
What's a likelihood ratio, and why does the calculator mention it?
A likelihood ratio (LR) compares how much more likely a result is under one hypothesis than another. It gives a second, independent way to reach the same posterior — multiply the prior odds by the LR — which this calculator uses as a built-in cross-check on the main calculation.