Bayes’ Theorem Calculator

Bayes' Theorem Calculator

Work out a posterior probability โ€” from a medical test, from two conditional probabilities, or from odds.

How common the condition is before testing
P(positive | condition)
P(negative | no condition)
Posterior probability ยท PPV
0.1667

With a 1% prevalence, a positive result is a true positive only 16.67% of the time โ€” the test is wrong about 5 times in 6 when the disease is rare.

NPV
0.9999
Likelihood ratio +
19.8
Prior odds
0.0101
Posterior odds
0.2000
Odds-form posterior
0.1667
P(positive) โ€” evidence
0.0594

Calculation

  1. Prior: P(D) = 0.0100, P(no D) = 0.9900.
  2. Likelihood ratio LR+ = sensitivity / (1 โˆ’ specificity) = 0.9900 / 0.0500 = 19.8000.
  3. P(positive) = 0.9900 ร— 0.0100 + 0.0500 ร— 0.9900 = 0.0594.
  4. PPV = P(D|positive) = 0.0099 / 0.0594 = 0.1667.
  5. NPV = 0.9999.
  6. Odds form: prior odds 0.0101 ร— LR+ 19.8 = 0.2000, posterior = 0.2000 / 1.2000 = 0.1667 โ€” agrees with the probability form.

Posterior vs prior โ€” sensitivity chart

How the posterior changes as the prior moves from 0 to 1, with sensitivity 99% and specificity 95% held fixed. The dot marks the current prior (1%).

Natural frequencies โ€” per 1,000 people. 10 have the condition: 9.9 test positive (true positives). 990 do not: 49.5 test positive (false positives). Of the 59.4 positive results, only 9.9 are true โ€” 9.9 / 59.4 = 0.1667.

A Bayes’ theorem calculator turns a prior probability into a posterior probability — the chance something is true after you see new evidence. Enter a disease prevalence, a test’s sensitivity and specificity, and it returns the chance a positive result is a true positive, the chance a negative result is a true negative, the likelihood ratio and the odds-form check. A test can be 99% accurate and still be wrong 5 times out of 6 — because when a disease is rare, most positives are false alarms.

How to use the Bayes’ theorem calculator

Choose the mode that matches what you have. Medical test is for a test with a sensitivity and a specificity. General is for any two conditional probabilities. Odds form is for when you already have odds and a likelihood ratio.

  1. Choose a mode: Medical test, General or Odds form.
  2. Enter the numbers: prevalence, sensitivity and specificity as percentages in Medical test mode; P(A), P(B|A) and P(B|not A) as decimals in General mode; prior odds and the likelihood ratio in Odds form mode.
  3. Click Calculate and read the headline posterior probability, then check the tiles for the negative predictive value, the likelihood ratio, the prior and posterior odds, and the odds-form cross-check.
  4. Read the calculation ledger for every step, the sensitivity chart to see how the posterior moves as the prior changes, and the natural-frequencies box for the same answer in whole people.

Try it now: prevalence 1%, sensitivity 99%, specificity 95% gives a posterior (positive predictive value) of 0.1667 and a negative predictive value of 0.9999 — a positive result is a true positive only about one time in six.

What is Bayes’ theorem?

Bayes’ theorem is the rule for updating a probability when new evidence arrives. Start with a prior probability P(A) — what you believed before the evidence. Then see evidence B, and update to the posterior probability P(A|B) — what you should believe after the evidence:

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

The three ingredients are the prior P(A), the likelihood P(B|A) (how likely the evidence is if A is true) and the evidence P(B) (how likely the evidence is overall). The evidence term is itself a sum over both possibilities: P(B) = P(B|A) × P(A) + P(B|not A) × P(not A). That is the whole calculation the calculator performs, in all three modes.

P(A|B) is not P(B|A). The chance of disease given a positive test is not the same as the chance of a positive test given disease — confusing the two is the prosecutor’s fallacy, and it has put innocent people in prison. The calculator keeps the direction straight: it always returns P(A|B), the probability you actually want. Read the guide to probability distributions for where conditional probability fits.

Base-rate neglect: why rare things fool us

People are bad at combining a test’s accuracy with how rare the thing being tested for is. A test that is right 99% of the time feels trustworthy, so a positive result feels like near-certain proof. But if only 1 person in 100 has the condition, then in 1,000 people there are just 10 cases and 990 healthy people — and the 5% false-positive rate on those 990 healthy people produces about 50 false alarms, dwarfing the 10 true positives. This is base-rate neglect: ignoring the prior. Bayes’ theorem is the correction. The sensitivity chart below the calculator shows the same point visually: as the prior rises, the posterior rises with it, steeply at first.

Natural frequencies beat percentages

Percentages hide the base rate; whole people reveal it. Instead of “1% prevalence, 99% sensitivity, 95% specificity”, say “out of 1,000 people, 10 have the condition and 990 do not; 9.9 of the 10 test positive, and 49.5 of the 990 test positive.” Now the answer is visible: 9.9 true positives out of 59.4 positive results, so about 1 in 6. The calculator’s natural-frequencies box does this translation for any numbers you enter. Use it whenever a posterior feels surprising — it usually makes the answer obvious.

Worked examples

Example 1: a medical test for a rare disease

A test for a disease that affects 1% of people has a sensitivity of 99% and a specificity of 95%. You test positive. What is the chance you actually have the disease? This is the worked example the calculator loads by default.

First, the likelihood ratio for a positive result: LR+ = sensitivity / (1 − specificity) = 0.99 / 0.05 = 19.8. A positive result is 19.8 times more likely in someone with the disease than in someone without it. That sounds decisive — but the prior odds are 1:99, or 0.0101, because only 1 person in 100 has the disease. Posterior odds = prior odds × LR+ = 0.0101 × 19.8 = 0.2000. Convert back: posterior = 0.2000 / (1 + 0.2000) = 0.1667.

The probability form agrees. P(positive) = 0.99 × 0.01 + 0.05 × 0.99 = 0.0099 + 0.0495 = 0.0594. PPV = 0.0099 / 0.0594 = 0.1667. And the negative predictive value is 0.9999: a negative result is almost certainly a true negative, because a negative is expected both from healthy people (95% of them test negative) and from the rare cases the test misses (1% of cases).

In natural frequencies, out of 1,000 people: 10 have the disease and 9.9 of them test positive; 990 do not and 49.5 of them test positive. So of the 59.4 positive results, only 9.9 are true positives — 9.9 / 59.4 = 0.1667. Rounded to whole people, that is 10 true positives out of about 60 positive results, or 10 / 60 ≈ 0.1667. The test is wrong 5 times out of 6, not because it is a bad test, but because the disease is rare.

Example 2: a spam filter

A spam filter sees the word “lottery”. 30% of all mail is spam, so P(spam) = 0.3. The word appears in 80% of spam, P(word|spam) = 0.8, and in 10% of ordinary mail, P(word|ham) = 0.1. What is the chance this message is spam?

P(spam|word) = P(word|spam) × P(spam) / P(word), where P(word) = 0.8 × 0.3 + 0.1 × 0.7 = 0.24 + 0.07 = 0.31. So P(spam|word) = 0.24 / 0.31 = 0.7742. Seeing the word lifts the chance from 0.3 to 0.7742. The odds form agrees: prior odds 0.3 / 0.7 = 0.4286, likelihood ratio 0.8 / 0.1 = 8, posterior odds 0.4286 × 8 = 3.4286, posterior 3.4286 / 4.4286 = 0.7742.

Edge cases: a prior of 0 or 1

If the prior is 0 — the event is impossible before the evidence — then the posterior is 0 no matter what the evidence says, because the numerator P(B|A) × 0 is 0. If the prior is 1 — the event is certain — then the posterior is 1. Bayes’ theorem cannot move a probability that is already 0 or 1; only evidence that changes the likelihoods matters in between. The calculator handles both ends without dividing by zero: a prior of 0 returns a posterior of 0, and a prior of 1 returns a posterior of 1.

One more check: with P(A) = 0.5, P(B|A) = 0.9 and P(B|not A) = 0.2, the posterior is P(A|B) = 0.9 × 0.5 / (0.9 × 0.5 + 0.2 × 0.5) = 0.45 / 0.55 = 0.8182. Try it in General mode.

Frequently asked questions

Why is the posterior so low when the test is 99% accurate?

Because accuracy is not the same as the chance a positive is true. A 99% sensitive test still misses 1% of cases, and a 95% specific test still flags 5% of healthy people. When the disease affects only 1% of people, the healthy group is 99 times larger, so its 5% false positives (about 50 per 1,000) swamp the 10 true cases. The posterior of 0.1667 counts both groups; the 99% figure only describes the test’s behaviour within the sick group. Raise the prevalence and the posterior rises with it — try 50% in the calculator and watch the posterior jump.

What is the odds form?

The odds form is Bayes’ theorem written with odds instead of probabilities: posterior odds = prior odds × likelihood ratio. Odds are the ratio of a probability to its complement (odds = p / (1 − p)), and they multiply cleanly, which is why the odds form is the quickest way to update by hand. In the medical example, prior odds 0.0101 × likelihood ratio 19.8 = posterior odds 0.2000, and converting back with p = odds / (1 + odds) gives 0.2000 / 1.2000 = 0.1667 — exactly the probability-form answer. The calculator shows both forms so you can cross-check them to four decimal places.

Sources: Bayes’ theorem and the odds form are the standard results for updating a probability with new evidence; the likelihood ratio and predictive values are the standard diagnostic-test quantities. All worked examples on this page were recomputed by hand and with the calculator above. Last updated 19 November 2026.

See all 91 free statistics tools.