Bayes' Theorem Calculator
Compute the posterior probability P(A|B) from a prior belief, a likelihood, and a false-positive rate. Use it for medical testing, spam filtering, or any scenario where you update beliefs with new evidence.
About this calculator
Bayes' theorem describes how to update a prior probability P(A) when new evidence B is observed. The formula is: P(A|B) = P(B|A) × P(A) / P(B), where the denominator P(B) is expanded using the law of total probability: P(B) = P(B|A) × P(A) + P(B|¬A) × (1 − P(A)). So the full expression is: P(A|B) = [P(B|A) × P(A)] / [P(B|A) × P(A) + P(B|¬A) × (1 − P(A))]. P(A) is the prior — your belief before seeing the evidence. P(B|A) is the likelihood — how probable the evidence is if A is true. P(B|¬A) is the false-positive rate — how probable the evidence is when A is false. The result P(A|B) is the posterior — your updated belief after observing B.
How to use
A medical test for a disease has 99% sensitivity (P(B|A) = 0.99) and a 5% false-positive rate (P(B|¬A) = 0.05). The disease prevalence is 1% (P(A) = 0.01). What is the probability you actually have the disease given a positive test? Numerator: 0.99 × 0.01 = 0.0099. Denominator: (0.99 × 0.01) + (0.05 × 0.99) = 0.0099 + 0.0495 = 0.0594. Posterior: 0.0099 / 0.0594 ≈ 0.1667, or about 16.7%. Despite a highly accurate test, low disease prevalence means most positives are false alarms.
Frequently asked questions
Why does a highly accurate medical test still produce many false positives?
When a disease is rare, even a small false-positive rate generates many false alarms relative to true positives, because there are far more healthy people than sick people in the tested population. This is directly captured by Bayes' theorem: a low prior P(A) suppresses the posterior even when the likelihood P(B|A) is high. For example, a 99% accurate test applied to a disease with 0.1% prevalence yields a posterior of only about 9%. This is called the base rate fallacy, and it is a critical consideration in screening program design.
What is the difference between prior probability and posterior probability in Bayes theorem?
The prior probability P(A) represents your degree of belief in hypothesis A before observing any new evidence — it may come from historical data, expert knowledge, or population statistics. The posterior probability P(A|B) is your updated belief after incorporating the new evidence B. The likelihood P(B|A) acts as the bridge, quantifying how well the hypothesis explains the observed evidence. Bayesian reasoning is iterative: today's posterior can become tomorrow's prior when fresh evidence arrives.
How is Bayes theorem used in spam email filtering?
Spam filters assign a prior probability that any incoming email is spam based on historical rates. For each word or feature in the email, the filter looks up P(word|spam) and P(word|not spam) from a training corpus — these are the likelihoods. Bayes' theorem combines these to compute the posterior probability that the email is spam given all its features. If the posterior exceeds a threshold (e.g. 90%), the email is flagged. This approach, called Naive Bayes classification, is robust, fast, and adapts as new spam patterns are observed.