Bayes' Theorem Calculator
Enter a prior P(A), a true-positive rate P(B|A) and a false-positive rate P(B|¬A) to get the posterior probability P(A|B), the evidence P(B), a step-by-step substitution and a probability tree. It is the fastest way to settle the classic false-positive paradox, runs entirely in your browser, and needs no signup.
How it works
Bayes' theoremupdates a prior belief about a hypothesis A once you observe evidence B. It rests on two simpler rules of probability and combines them into a single formula. Throughout, let A be the event of interest (“has the condition”, “is spam”) and B the observed evidence (“tests positive”, “contains the word”).
The full statement, with the denominator expanded, is:
P(A|B) = P(B|A)·P(A) / [ P(B|A)·P(A) + P(B|¬A)·P(¬A) ]
- Complement the prior.P(¬A) = 1 − P(A). This is the basic complement axiom of probability (Grinstead & Snell).
- Find the evidence by total probability. The chance of seeing B at all splits across the two ways it can happen — when A is true and when A is false:
P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A)
This marginal P(B) is the normalising constant. Source: NIST/SEMATECH e-Handbook; Grinstead & Snell §4. - Apply Bayes' theorem. Divide the true-positive term by the evidence to get the posterior P(A|B) = P(B|A)·P(A) / P(B). This is the same rule scikit-learn states for Naive Bayes, P(y|x) = P(y)·P(x|y) / P(x).
- Complement the posterior. P(¬A|B) = 1 − P(A|B), the probability that A is false despite the evidence.
The calculator above also recomputes the posterior a second, independent way — the odds form. The prior odds P(A)/P(¬A) are multiplied by the likelihood ratio P(B|A)/P(B|¬A) to give the posterior odds, which convert back to a probability via odds / (1 + odds). Because this uses a ratio of ratios rather than the normalisation above, agreement between the two routes is a genuine correctness check, and the four joint probabilities of the tree are confirmed to sum to 1. When a likelihood is 0 the evidence can vanish (P(B) = 0); the tool then reports the posterior as undefined rather than dividing by zero.
A key intuition the tool makes visible: the posterior depends heavily on the base rate. A highly sensitive test applied to a rare condition still produces mostly false positives, because the large healthy population contributes many false alarms while the small affected population contributes few true ones. That is the false-positive paradox, and the probability tree shows exactly where the numbers come from.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — Naive Bayes (states Bayes' theorem and its use in classification)
- NIST/SEMATECH e-Handbook of Statistical Methods — conditional probability and total-probability rules
- Grinstead & Snell — Introduction to Probability (open access, AMS) — Bayes' theorem derivation
The formulas on this page were last cross-checked against these sources on 2026-06-11. Bayes' theorem is a stable mathematical identity, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.