Bayes' theorem answers a question that comes up constantly, and that people get wrong shockingly often, even trained professionals: given some new evidence, how should you update a belief you already held? A medical test comes back positive β how worried should you actually be? A spam filter flags an email β how likely is it genuinely spam? Bayes' theorem provides the exact, mathematically correct way to combine prior knowledge with new evidence, and the results are frequently far less dramatic than intuition suggests.
- The formula, and what each term (prior, likelihood, posterior) actually represents
- The classic medical testing example β and why a positive result matters less than most people assume
- Why base rates matter so much, and how ignoring them causes real errors
- How Bayesian thinking differs from the frequentist approach used elsewhere in this course
The Formula
Thomas Bayes, an 18th-century English statistician and Presbyterian minister, developed the core idea in a paper published only after his death, in 1763. It went largely unnoticed for over a century before becoming one of the two dominant philosophical frameworks β alongside the frequentist approach developed later by Fisher, Neyman, and Pearson β through which essentially all of modern statistics is practiced today.
Each term has a name worth learning, because they'll come up constantly in any discussion of Bayesian methods:
- P(A) β the prior: your belief about A before seeing the new evidence B.
- P(B|A) β the likelihood: how probable the evidence B is, if A is actually true.
- P(B) β the overall probability of the evidence B occurring at all, regardless of whether A is true or not.
- P(A|B) β the posterior: your updated belief about A, after accounting for the evidence B.
In plain language: Bayes' theorem takes what you believed before (the prior), combines it with how well the new evidence fits that belief (the likelihood), and produces an updated, more informed belief (the posterior).
The Classic Example: Medical Testing
Problem: A disease affects 1% of the population. A test for it is 95% accurate (correctly identifies 95% of people who have the disease, and correctly clears 95% of people who don't). A random person tests positive. What's the actual probability they have the disease?
Most people's gut instinct is "95%," matching the test's stated accuracy. This is wrong, often dramatically so β and Bayes' theorem shows exactly why.
Let A = has the disease, B = tests positive.
P(A) = 0.01 (the base rate β 1% of the population has the disease)
P(B|A) = 0.95 (true positive rate β probability of testing positive given you have the disease)
P(B) needs to be calculated by considering both ways of testing positive: truly having the disease and testing positive, OR not having the disease and getting a false positive:
P(B) = P(B|A)Β·P(A) + P(B|not A)Β·P(not A) = (0.95)(0.01) + (0.05)(0.99) = 0.0095 + 0.0495 = 0.059
P(A|B) = P(B|A)Β·P(A) / P(B) = (0.95)(0.01) / 0.059 = 0.0095 / 0.059 β 0.161, or about 16.1%
Despite a "95% accurate" test coming back positive, the actual probability of having the disease is only about 16% β far lower than intuition suggests. This isn't a flaw in the test; it's the mathematically correct consequence of the disease being rare. Because so few people actually have the disease (1%), even a small 5% false-positive rate among the enormous healthy majority produces more false positives in absolute terms than true positives among the small diseased minority.
This result is sometimes called the "base rate fallacy" when people get it wrong β the instinct to focus entirely on the test's accuracy (P(B|A)) while ignoring how rare the condition actually is (P(A)) beforehand. The rarer the underlying condition, the more a positive result on an imperfect test should be treated with caution, not alarm, until a second, more targeted test is run β this is exactly why doctors typically order a confirmatory test after an initial positive screening result, rather than acting on the first result alone.
A Second Worked Example: Spam Filtering
Problem: 20% of all emails are spam. The word "free" appears in 40% of spam emails but only 5% of legitimate emails. If an email contains the word "free," what's the probability it's spam?
P(spam) = 0.20, P("free"|spam) = 0.40, P("free"|not spam) = 0.05, P(not spam) = 0.80
P("free") = (0.40)(0.20) + (0.05)(0.80) = 0.08 + 0.04 = 0.12
P(spam|"free") = (0.40)(0.20) / 0.12 = 0.08/0.12 β 0.667, or about 66.7%
Seeing the word "free" more than triples the probability of spam, from a 20% prior up to a 67% posterior β this exact calculation, run across many words simultaneously, is the underlying logic of real Bayesian spam filters, which is why they were among the first genuinely effective automated spam-detection systems.
Sequential Updating: Bayes' Theorem in Action Over Time
One of the most powerful features of Bayesian reasoning is that it naturally handles multiple pieces of evidence arriving over time β today's posterior simply becomes tomorrow's prior, ready to be updated again with the next piece of evidence. A doctor who orders a second confirmatory test after an initial positive result is, whether or not they'd describe it this way, running exactly this update: the 16% posterior from the first test becomes the new prior for interpreting the second test's result, producing a considerably more confident final estimate if the second test also comes back positive.
Bayesian vs. Frequentist Thinking
Most of the hypothesis testing and confidence interval material elsewhere on this site follows the frequentist approach, which treats probability as a long-run frequency β the proportion of times an event would occur across infinite repeated trials, and treats population parameters as fixed, unknown constants. The Bayesian approach instead treats probability as a genuine degree of belief, which can be assigned even to fixed, one-off, non-repeatable events (like "the probability this specific defendant is guilty"), and updates that belief formally as new evidence arrives, using exactly the mechanism shown above. Both are mathematically rigorous, internally consistent frameworks β they differ in philosophy and interpretation, not in whether the underlying mathematics is valid.
Real-World Applications
Legal reasoning: Bayes' theorem is directly relevant to how forensic evidence should be interpreted in court β the "prosecutor's fallacy" is exactly the base-rate error described above, applied to a courtroom: confusing "the probability of this DNA match if the defendant is innocent" with "the probability the defendant is innocent given this DNA match." Several real wrongful convictions have been traced directly to this exact confusion being presented to juries as if the two probabilities were the same.
Machine learning: the Naive Bayes classifier β a genuinely simple but surprisingly effective algorithm still used in production spam filters and text classification systems β applies exactly the calculation shown above across many pieces of evidence (words) simultaneously, multiplying likelihoods together under a simplifying assumption of independence between features.
A/B testing and business decisions: Bayesian approaches to A/B testing update a belief about which version of a webpage or product performs better as data streams in, rather than waiting for a fixed sample size before drawing any conclusion β letting decision-makers see a continuously updated probability that version B is better, rather than a single pass/fail significance verdict at the end.
Weather forecasting: "70% chance of rain" is fundamentally a Bayesian-style probability statement, built by combining historical base rates for similar atmospheric conditions with current sensor evidence, continuously updated as new data arrives throughout the day.
Common Mistakes
Swapping P(A|B) and P(B|A). This is, by a wide margin, the single most common error involving Bayes' theorem β treating "probability of evidence given the hypothesis" as if it were the same as "probability of the hypothesis given the evidence." As the medical testing example shows, these can differ by a factor of six or more.
Forgetting to account for false positives when calculating P(B). It's tempting to just use P(B|A) directly as if it were the final answer, skipping the denominator calculation entirely β but P(B) must account for every way the evidence could have arisen, including from the "not A" case, or the whole calculation collapses.
Treating an outdated prior as still valid. A prior probability calculated from old data (like disease prevalence from years ago) may no longer reflect current reality β Bayesian updating is only as good as the prior it starts from, and a stale prior can distort the posterior even with perfectly accurate new evidence.
Why is the base rate so easy to ignore in practice?
What happens if the prior probability is completely unknown?
Is Bayes' theorem the same as Bayesian statistics?
Share this article
Written by
Statistics Fundamentals Editorial Team
Written and reviewed by our team of statistics educators. Content is aligned with GCSE, A-Level, AP Statistics, and undergraduate curricula.
About Statistics Fundamentals β