Bayes' Theorem Calculator

Enter a prior, likelihood and false-positive rate to compute the posterior probability P(A|B). Includes a medical-test preset and a natural-frequency population grid that makes the counter-intuitive results click.

What is Bayes' theorem?

Bayes' theorem is a rule for updating a probability when new evidence arrives. You start with a prior belief P(A), see some evidence B, and end with a posterior belief P(A|B). The formula, the law of total probability that expands the denominator, and the base-rate intuition are all covered in the guide cards below.

Bayes' theorem explained, piece by piece

Each card below owns one part of Bayes' theorem — the formula itself, the law of total probability, the base-rate fallacy, and sequential updating — with a plain-English explanation, the formula (every symbol spelled out), a diagram, and a worked example in one place.

The formula — posterior, likelihood, prior, evidence

Bayes' theorem updates a probability when new evidence arrives. Start with a prior belief P(A), see evidence B, and finish with a posterior P(A|B). The numerator is 'the evidence weighted by the prior'; the denominator normalises by the total probability of the evidence.

P(A|B) = P(B|A) · P(A) / P(B)
P(A)prior — belief before evidence·P(B|A)likelihood — chance of evidence when A is true·P(B|¬A)false-positive rate·P(A|B)posterior — updated belief
P(A|B) = P(B|A)·P(A) / P(B)posterior = likelihood × prior ÷ evidenceP(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A)
Example
Given
P(A)=0.001
P(B|A)=0.99
P(B|¬A)=0.05
Substitute
(0.99·0.001) / (0.99·0.001 + 0.05·0.999)
Answer
P(A|B) ≈ 0.0194 (1.94%)

Law of total probability — computing P(B)

You never observe P(B) directly. You expand it as 'the two ways B can happen': B with A true (true positives) plus B with A false (false positives). This expansion is what turns the abstract Bayes formula into something you can actually compute.

P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A)
P(¬A)= 1 − P(A)·TPtrue positives = P(B|A)·P(A)·FPfalse positives = P(B|¬A)·P(¬A)
P(A)P(¬A)P(B|A)P(B|¬A)TPFPP(B) = TP + FP
Example
Given
P(A)=0.001
P(B|A)=0.99
P(B|¬A)=0.05
Substitute
0.99·0.001 + 0.05·0.999 = 0.00099 + 0.04995
Answer
P(B) ≈ 0.05094

Base-rate fallacy — why a positive test can still likely be wrong

When the condition is rare, the false-positive count almost always dwarfs the true-positive count. The most accurate way to see this is with natural frequencies: draw a picture of the population and count the boxes rather than juggling percentages.

P(A|B) = TP / (TP + FP)
TPtrue positives in the population·FPfalse positives in the population
1 true positive (green) vs 5 false positives (red)
Example
Given
100 people: 1 sick (test positive) + 5 healthy (false positive)
Substitute
1 / (1 + 5)
Answer
≈ 16.7% — nowhere near the 99% sensitivity would suggest

Sequential updating — the posterior becomes the next prior

Bayes' theorem chains. After one positive test your posterior is (say) 2%. That 2% becomes the prior for the next test. Two independent positive results move you from 0.1% to 2% to well over 30% — this is why confirmatory testing exists.

P(A|B₁∩B₂) = P(B₂|A) · P(A|B₁) / P(B₂)
B₁first piece of evidence·B₂second, independent piece·P(A|B₁)posterior after first test = new prior
prior0.1%posterior~2%2nd test~30%+
Example
Given
prior 0.1% → after one positive ≈ 2% → after a second independent positive
Substitute
(0.99·0.02) / (0.99·0.02 + 0.05·0.98)
Answer
≈ 28.8%

P(B|A) and P(A|B) are not the same thing

The most common Bayes mistake is treating "probability of a positive test given disease" and "probability of disease given a positive test" as the same number. They are often wildly different, and Bayes' theorem is the exact tool for converting one into the other.

Common mistakes

  • Ignoring the base rate. A 99%-accurate test on a 0.1% disease is not "99% likely you have it".
  • Swapping P(B|A) and P(A|B). They are different quantities.
  • Forgetting the false-positive rate. Without P(B|¬A) you cannot compute P(B), so you cannot apply Bayes.
  • Entering percentages as whole numbers. This calculator expects decimals in 0–1.
  • Assuming the evidence is decisive. If P(B|A) and P(B|¬A) are close, the test tells you very little.

Features of this calculator

  • Inputs for the prior P(A), likelihood P(B|A) and false-positive rate P(B|¬A) — computes the posterior P(A|B) in one click
  • Medical-test and spam-filter presets pre-fill realistic numbers you can tweak
  • Natural-frequency grid — a 1000-cell population picture with true/false positives and negatives color-coded
  • Show/hide step-by-step working: complement, law-of-total-probability expansion for P(B), the Bayes substitution, and a natural-frequency check
  • Custom labels — rename A and B so the output reads like your actual problem
  • Copy the result summary or download the panel — grid, result and steps — as an image

Frequently asked questions

+What does Bayes' theorem calculate?

The posterior probability P(A|B) — your updated belief that A is true after observing evidence B.

+Do I enter percentages or decimals?

Decimals in the range 0 to 1. 5% is 0.05, not 5.

+What is the law of total probability?

The rule P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A). It adds the two ways B can happen and gives the denominator of Bayes.

+Why is the natural-frequency picture more intuitive?

Because it converts abstract probabilities into whole-person counts. "50 false positives out of 999 healthy people" is impossible to ignore.

+Can I use Bayes' theorem with more than two hypotheses?

Yes — the general form sums over every mutually exclusive hypothesis in the denominator. This calculator handles the common two-outcome case.

Related calculators