Bayes' Theorem Calculator
Calculate posterior probability using Bayes' theorem. Enter prior probability, likelihood, and false positive rate to find P(A|B). See step-by-step solution with odds ratios. See also our Conditional Probability Calculator, Probability Calculator, and Normal Distribution Calculator.
How to Use the Bayes' Theorem Calculator
Bayes' theorem calculates the probability of a hypothesis given observed evidence. It updates your prior belief P(A) using new evidence to produce a posterior probability P(A|B). This is fundamental to medical diagnosis, spam filtering, machine learning, and any situation where you need to revise probabilities based on new information.
Enter three values: P(A) is your prior probability (how likely the hypothesis is before seeing evidence), P(B|A) is the likelihood (probability of seeing the evidence if the hypothesis is true), and P(B|¬A) is the false positive rate (probability of seeing the evidence if the hypothesis is false). The calculator computes the posterior probability P(A|B) and shows the step-by-step derivation.
A classic example is medical testing: if a disease affects 1% of the population (prior = 0.01), a test detects it 95% of the time (sensitivity = 0.95), and has a 5% false positive rate, then a positive test result only means about 16% chance of actually having the disease. This counterintuitive result demonstrates why base rates matter enormously in probability reasoning.
The likelihood ratio (P(B|A)/P(B|¬A)) is a key quantity that determines how much the evidence shifts your belief. A likelihood ratio of 1 means the evidence is equally likely under both hypotheses and provides no information. Ratios above 10 are considered strong evidence, and above 100 very strong. The odds form of Bayes' theorem (posterior odds = prior odds × likelihood ratio) is often more intuitive for sequential updating.
Formula
Bayes' Theorem:
P(A|B) = P(B|A) × P(A) / P(B)
Total Probability (denominator):
P(B) = P(B|A)×P(A) + P(B|¬A)×P(¬A)
Odds Form:
Posterior Odds = Prior Odds × Likelihood Ratio
Prior Odds = P(A) / P(¬A)
Likelihood Ratio = P(B|A) / P(B|¬A)
Sensitivity and Specificity:
Sensitivity = P(B|A) = True Positive Rate
Specificity = P(¬B|¬A) = 1 - False Positive Rate
Positive Predictive Value:
PPV = P(A|B) = Sensitivity × Prevalence / P(B)
Example Calculation
Medical test: Disease prevalence 1%, test sensitivity 95%, false positive rate 5%
P(A) = 0.01, P(B|A) = 0.95, P(B|¬A) = 0.05
P(B) = 0.95×0.01 + 0.05×0.99 = 0.0095 + 0.0495 = 0.059
P(A|B) = 0.95×0.01 / 0.059 = 0.0095/0.059 = 0.161
Result: Only 16.1% chance of having the disease given a positive test!
Likelihood Ratio = 0.95/0.05 = 19
Prior Odds = 0.01/0.99 = 0.0101
Posterior Odds = 0.0101 × 19 = 0.192
Reference Table
| Test/Scenario | Prior | Sensitivity | False Pos | Posterior |
|---|---|---|---|---|
| Cancer Screening | 0.01 | 0.90 | 0.05 | 0.154 |
| COVID Rapid Test | 0.05 | 0.85 | 0.02 | 0.691 |
| Drug Test | 0.04 | 0.99 | 0.01 | 0.805 |
| Pregnancy Test | 0.30 | 0.99 | 0.01 | 0.977 |
| Spam Filter | 0.20 | 0.95 | 0.05 | 0.826 |
| Rare Disease | 0.001 | 0.99 | 0.05 | 0.019 |
| Airport Security | 0.0001 | 0.95 | 0.10 | 0.001 |
| DNA Match | 0.001 | 0.9999 | 0.0001 | 0.909 |
Frequently Asked Questions
What is Bayes' theorem?
Bayes' theorem is a mathematical formula for updating probabilities based on new evidence. Named after Reverend Thomas Bayes (1701-1761), it describes how to calculate the probability of a hypothesis given observed data. It is the foundation of Bayesian statistics, machine learning algorithms, medical diagnostics, and rational decision-making under uncertainty. The theorem shows how prior beliefs should be revised in light of new evidence.
Why is the posterior often surprisingly low for medical tests?
When a disease is rare (low prior probability), even a highly accurate test produces many false positives relative to true positives. If 1% have the disease and you test 10,000 people: 100 have it (95 test positive), 9,900 don't have it (495 test positive). So 95 out of 590 positive results are true positives = 16.1%. This is called the base rate fallacy — people ignore how rare the condition is when interpreting test results.
What is the likelihood ratio?
The likelihood ratio is P(B|A)/P(B|¬A) — how much more likely the evidence is under the hypothesis versus the alternative. A likelihood ratio of 10 means the evidence is 10 times more likely if the hypothesis is true. It directly multiplies the prior odds to give posterior odds. Likelihood ratios above 10 are considered strong evidence; above 100 is very strong. This is often more intuitive than working with raw probabilities.
How is Bayes' theorem used in spam filtering?
Bayesian spam filters calculate P(spam|words) — the probability an email is spam given the words it contains. The prior P(spam) is the overall spam rate. For each word, P(word|spam) and P(word|not spam) are estimated from training data. The filter multiplies likelihood ratios for all words to update the probability. Words like "viagra" have high likelihood ratios for spam, while "meeting" has low ratios. This approach adapts to new spam patterns over time.
What is the difference between prior and posterior?
The prior P(A) is your belief about the probability before seeing any evidence — it represents background knowledge or base rates. The posterior P(A|B) is your updated belief after observing evidence B. Bayes' theorem provides the mathematically correct way to update from prior to posterior. The posterior from one analysis can become the prior for the next piece of evidence, allowing sequential updating as more data arrives.
Can I apply Bayes' theorem multiple times?
Yes. Sequential Bayesian updating uses the posterior from one observation as the prior for the next. If you get a positive test result (posterior = 0.16), then get a second independent positive test, use 0.16 as the new prior. This iterative process converges toward the truth as more evidence accumulates. Each piece of evidence shifts the probability, with stronger evidence causing larger shifts. This is how Bayesian learning works in AI systems.