Bayes' Theorem Calculator
Compute the posterior probability P(A|B) using Bayes' theorem. Use it when you want to update a prior belief about event A after observing new evidence B — common in medical testing, spam filtering, and risk analysis.
About this calculator
Bayes' theorem describes how to update the probability of a hypothesis after observing evidence. The core formula is P(A|B) = P(A) × P(B|A) / P(B), where P(A) is the prior probability of A before seeing evidence, P(B|A) is the likelihood of observing B given A is true, and P(B) is the total probability of observing B across all scenarios. The result, P(A|B), is called the posterior probability — your updated belief about A after observing B. This framework is foundational in statistics, machine learning, and Bayesian inference. It allows rational belief revision: strong prior evidence combined with a high likelihood will yield a high posterior, while weak priors or low likelihoods will temper the result significantly.
How to use
Suppose a disease affects 1% of the population, P(A) = 0.01. A test correctly detects the disease 90% of the time, so P(B|A) = 0.90. The overall probability of a positive test result, P(B), is 0.108 (accounting for false positives). Applying the formula: P(A|B) = (0.01 × 0.90) / 0.108 = 0.009 / 0.108 ≈ 0.0833. So even with a positive test, there is only an 8.3% chance the patient actually has the disease — a counterintuitive but critically important result.
Frequently asked questions
What is the difference between prior probability and posterior probability in Bayes' theorem?
The prior probability P(A) represents your belief in hypothesis A before any new evidence is observed. The posterior probability P(A|B) is your updated belief after taking new evidence B into account. Bayes' theorem provides the exact mathematical rule for performing this update. The difference between the two reflects how much the evidence shifts your belief — strong evidence causes a large shift, while weak evidence causes little change.
When should I use Bayes' theorem instead of classical probability?
Use Bayes' theorem whenever you have prior knowledge about a hypothesis and want to update that belief in light of new data. Classical probability treats all outcomes equally, but Bayesian reasoning incorporates prior information, making it ideal for medical diagnosis, fraud detection, and spam classification. It is especially powerful in situations where base rates matter — for example, a positive test for a rare disease is still unlikely to mean illness if the base rate is very low. Any time you need to reason about conditional relationships, Bayes' theorem is the right tool.
Why does a high-accuracy test sometimes give a misleading posterior probability?
This phenomenon — often called the base rate fallacy — occurs when the prior probability of a condition is very low. Even if a test is 99% accurate, a positive result may still be more likely a false positive than a true positive when the condition affects only 1 in 10,000 people. Bayes' theorem makes this explicit by forcing you to account for P(B), the total probability of a positive test across the entire population. Ignoring base rates leads to overconfidence in test results and is a common error in medical and legal reasoning.