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' theorem updates 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.
Where the formula comes from
Bayes' theorem is not an extra assumption; it falls straight out of the definition of conditional probability. By definition P(A|B) = P(A∩B) / P(B) and P(B|A) = P(A∩B) / P(A). Both share the joint term P(A∩B), so P(A∩B) = P(B|A)·P(A). Substituting that into the first definition gives P(A|B) = P(B|A)·P(A) / P(B). Grinstead & Snell derive it the same way in their chapter on conditional probability. The only extra ingredient is the denominator: because A and ¬A split every outcome into two non-overlapping groups, P(B) is the sum of the two branches of the tree that end in B.
Updating more than once
The posterior from one piece of evidence can become the prior for the next, provided the two pieces of evidence are conditionally independent given A (for example, two separate tests whose errors are unrelated). Run the calculator, copy P(A|B) back into the prior field, and apply the second likelihoods. In odds form this is simply multiplying the prior odds by one likelihood ratio per test. If the tests share a cause of error, such as the same lab or the same sample, this shortcut overstates your confidence.
Edge cases the calculator handles
- P(A) = 0 or 1. A prior of exactly 0 or 1 can never move: no evidence changes a certainty. The odds form is undefined at P(A) = 1 (the odds are infinite), so only the direct formula is shown.
- P(B|¬A) = 0. If B never happens without A, one observation of B proves A: the posterior is 1 for any non-zero prior. The likelihood ratio is infinite, so the odds cross-check is skipped.
- P(B|A) = P(B|¬A). The likelihood ratio is 1, the evidence tells you nothing, and the posterior equals the prior. This is a quick way to spot a useless test.
- Both likelihoods 0. P(B) = 0 and the posterior is undefined, as described above.
If you are starting from a table of counts (true positives, false positives and so on) rather than rates, the diagnostic test statistics calculator turns them into sensitivity, specificity and predictive values. Its positive predictive value is the same number this page calls the posterior.
Worked examples
Common mistakes when applying Bayes' theorem
Most wrong answers to Bayes problems come from a small set of habits. Check your working against these before trusting a result.
- Entering specificity instead of the false-positive rate. A test described as “95% specific” has P(B|¬A) = 0.05, not 0.95. Entering 0.95 makes the evidence almost useless and the posterior collapses toward the prior.
- Ignoring the base rate. Using the test's accuracy as the answer (“the test is 99% accurate, so I am 99% likely to be sick”) skips the prior entirely. The same test gives very different posteriors in a population where the condition is common and in one where it is rare.
- Mixing percentages and decimals. Typing 1 for a 1% prior in probability mode means certainty. Switch the input format to percentage mode, or divide by 100 first.
- Treating dependent tests as independent. Repeating the same test on the same sample usually repeats the same error, so chaining posteriors (as in the retesting example) is only valid when the errors are unrelated.
- Reading odds as probabilities. Posterior odds of 3.96 mean 3.96 to 1, which is a probability of 0.7984, not 3.96. If you work with odds ratios from studies, the odds ratio and relative risk calculator shows how the two scales relate.
The same arithmetic sits behind classifier evaluation. A spam filter or a medical model produces a confusion matrix, and the precision in that matrix is Bayes' posterior for a positive prediction. You can build one from raw counts with the confusion matrix calculator. When one trial becomes many, for example the chance of at least k positives out of n independent tests, the binomial distribution calculator picks up from there.
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-09-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.