ScienceMarch 29, 2026

Bayes' Theorem Explained: Formula, Examples & Medical Testing

By The hakaru Team·Last updated March 2026

Quick Answer

  • *Bayes' theorem is a formula for updating a probability estimate when you receive new evidence. It converts a prior belief into a posterior probability using observed data.
  • *The core formula: P(A|B) = P(B|A) × P(A) / P(B)
  • *A test that is 95% accurate can still produce mostly false positives when the disease it screens for is rare — a counterintuitive result called the base rate fallacy.
  • *Bayes' theorem is used in medical diagnosis, spam filters, machine learning, and courtroom evidence analysis.

What Is Bayes' Theorem?

Bayes' theorem is a mathematical rule for combining prior beliefs with new evidence to produce an updated probability estimate. Named after the 18th-century English statistician and minister Thomas Bayes, it answers one fundamental question: Given that I observed this evidence, how likely is my hypothesis to be true?

In everyday language: you start with a baseline probability (the prior), observe something new (the evidence), and compute a revised probability (the posterior). The formula tells you exactly how much to update your belief.

Research by Nobel laureate Daniel Kahneman and Amos Tversky — published in Psychological Review(1973) — found that humans are systematically poor at this kind of updating. We tend to overweight vivid evidence and ignore base rates. Bayes' theorem is the antidote.

The Bayes' Theorem Formula

The formula is:

P(A|B) = P(B|A) × P(A) / P(B)

Where:

  • P(A|B) — Posterior probability: the probability of A given that B occurred
  • P(B|A) — Likelihood: the probability of observing B if A is true
  • P(A) — Prior probability: your initial estimate of A before seeing evidence
  • P(B) — Marginal probability: the total probability of observing B under all scenarios

The denominator P(B) can be expanded as: P(B) = P(B|A) × P(A) + P(B|¬A) × P(¬A)

You do not need to memorize these expansions. Our Bayes theorem calculator handles the math — just enter your prior, sensitivity, and specificity.

4 Steps to Apply Bayes' Theorem

Follow these four steps for any Bayesian probability problem:

  1. Set the prior P(A): What is the base rate? For a disease, this is prevalence in the population being tested.
  2. Identify the likelihood P(B|A): If the hypothesis is true, how probable is the observed evidence? For a medical test, this is sensitivity (true positive rate).
  3. Find the false positive rate P(B|¬A): How often does the evidence appear when the hypothesis is false? For a test, this is 1 minus specificity.
  4. Apply the formula: Plug the numbers into P(A|B) = P(B|A) × P(A) / P(B) to get your posterior probability.

The Medical Testing Example: Why Accurate Tests Mislead

This is the most important application of Bayes' theorem — and the most counterintuitive. Consider a disease with a 1% prevalence in the population being screened. A test has 95% sensitivity (true positive rate) and 95% specificity (true negative rate). You test positive. What is the actual probability you have the disease?

Most people guess 95%. The real answer is about 16%.

ScenarioPrior P(A)Sensitivity P(B|A)SpecificityPosterior P(A|B+)
Rare disease (1% prevalence)1%95%95%16.1%
Moderate prevalence (10%)10%95%95%67.9%
High-risk group (30%)30%95%95%89.0%
High-risk group (50%)50%95%95%95.0%

The table shows that the same test produces a wildly different positive predictive value (PPV) depending on who is being tested. At 1% prevalence, roughly 84% of positive results are false positives. At 50% prevalence, the PPV matches the test's accuracy.

A 2020 study in JAMA Internal Medicinefound that even experienced clinicians consistently overestimate the positive predictive value of diagnostic tests, largely because they do not account for base rates. Bayes' theorem is not optional knowledge for medical decision-making — it is essential.

The Math Step by Step (1% Prevalence, 95%/95% Test)

Start with 10,000 people. With 1% prevalence, 100 have the disease and 9,900 do not.

  • True positives: 100 × 0.95 = 95
  • False positives: 9,900 × 0.05 = 495
  • Total positive tests: 95 + 495 = 590
  • Positive predictive value: 95 / 590 = 16.1%

Fewer than 1 in 6 positive results corresponds to a real case. This is why mass screening programs for rare diseases require follow-up confirmatory testing — and why understanding Bayes' theorem can prevent unnecessary anxiety and treatment.

COVID-19 Rapid Tests: A Real-World Bayesian Case

A 2021 study published in PLOS ONE evaluated lateral flow antigen (LFA) tests for COVID-19, finding sensitivity of approximately 72% and specificity of 99.6% under real-world conditions. At 10% community prevalence:

  • PPV (probability of disease given positive test): approximately 95%
  • NPV (probability of no disease given negative test): approximately 97%

But at 1% prevalence (late pandemic, low community spread), the same test's PPV dropped to roughly 64%— meaning more than one in three positives was false. This explains why public health guidelines recommended confirmatory PCR testing after a positive rapid test during low-prevalence periods.

5 Real-World Uses of Bayesian Reasoning

  1. Medical diagnosis:Bayesian reasoning underlies clinical decision support tools. A patient with chest pain has different posterior probabilities for cardiac events depending on age, sex, and risk factors — the prior changes the interpretation of identical test results.
  2. Spam email filtering: Naive Bayes classifiers are among the most effective spam filters. They compute the posterior probability that an email is spam given the words it contains, updating beliefs word by word. Gmail and most major email providers still use Bayesian components in their filters.
  3. Legal evidence: The likelihood ratio is used in forensic science to evaluate DNA evidence, fingerprints, and other probabilistic findings. A 2011 report by the UK Royal Statistical Society recommends using likelihood ratios in court to express the strength of forensic evidence.
  4. A/B testing and conversion optimization:Bayesian A/B testing calculates the probability that variant B outperforms variant A, updating continuously as data arrives. This avoids the “peeking problem” that plagues frequentist tests.
  5. Machine learning:Bayesian neural networks, Gaussian processes, and probabilistic programming frameworks (like PyMC and Stan) use Bayes' theorem to quantify uncertainty in model predictions — critical in high-stakes applications like autonomous vehicles and medical AI.

Likelihood Ratios: A Practical Shortcut

Instead of applying the full formula every time, clinicians and analysts often use likelihood ratios (LR). The positive likelihood ratio is:

LR+ = Sensitivity / (1 − Specificity)

A useful rule of thumb (from Jaeschke et al., JAMA, 1994):

Positive LR ValueInterpretation
> 10Large, often conclusive increase in probability
5 – 10Moderate increase in probability
2 – 5Small increase in probability
1 – 2Minimal, rarely important
< 1Decreases probability

For the 95%/95% test above: LR+ = 0.95 / (1 − 0.95) = 19. That's a strong test — but it cannot overcome a very low prior. Starting odds of 1:99 (1% prior) multiplied by 19 gives posterior odds of 19:99, or about 16% probability.

Common Mistakes When Applying Bayes' Theorem

Ignoring the Base Rate

Kahneman and Tversky's research identified the base rate neglectbias: people focus on the vivid evidence (a positive test) and ignore the prior (how common the disease is). The prior probability is not optional — it fundamentally determines the posterior.

Confusing P(A|B) with P(B|A)

This mistake — called the prosecutor's fallacy— occurs when someone treats “the probability of this evidence given innocence” as equivalent to “the probability of innocence given this evidence.” They are different numbers, often by orders of magnitude.

Treating a Negative Test as a Guarantee

A test with 90% sensitivity misses 10% of true cases. The posterior probability after a negative test depends on both the prior and the test's sensitivity. For high-prior scenarios, a negative test still leaves meaningful residual probability.

Applying a Fixed Prior to a Different Population

A test validated on one population (e.g., hospitalized patients) may have very different performance characteristics — and very different relevant base rates — in another population (e.g., community screening). Always match the prior to the population being tested.

Calculate posterior probabilities instantly

Use our free Bayes Theorem Calculator →

Frequently Asked Questions

What is Bayes' theorem in simple terms?

Bayes' theorem is a formula for updating a probability estimate when you receive new evidence. You start with a prior belief (e.g., 1% of people have a disease), observe evidence (a positive test), and calculate a posterior probability — the revised chance the belief is true given that evidence.

Why does a 95% accurate test still produce many false positives?

When a disease is rare — say 1 in 1,000 people — even a test with 95% sensitivity and 95% specificity yields mostly false positives. Among 1,000 people, roughly 1 has the disease (true positive) while 50 healthy people test positive (false positives). The positive predictive value is only about 2%.

What is the difference between prior and posterior probability?

Prior probability is your initial estimate before seeing new evidence — for example, the base rate of a disease in the general population. Posterior probability is the updated estimate after incorporating evidence, such as a positive test result. Bayes' theorem is the formula that converts prior to posterior.

What is a likelihood ratio in Bayesian reasoning?

A likelihood ratio (LR) measures how much a test result shifts your probability estimate. A positive LR above 10 is considered strong evidence; below 0.1 is strong evidence against a condition. For a test with 90% sensitivity and 10% false-positive rate, the positive LR is 9 — it multiplies your odds by 9.

Where is Bayes' theorem used in real life?

Bayes' theorem is used in medical diagnosis, spam email filters, courtroom evidence evaluation, weather forecasting, and machine learning classifiers. It underpins Naive Bayes classifiers, A/B test analysis, and the field of Bayesian statistics used widely in scientific research.

How do I calculate posterior probability step by step?

Four steps: (1) Set your prior probability P(A) — the base rate. (2) Identify the likelihood P(B|A) — how probable the evidence is if A is true. (3) Calculate the marginal probability P(B) — the total probability of the evidence across all scenarios. (4) Apply the formula: P(A|B) = P(B|A) × P(A) / P(B).