Bayes' Theorem Calculator

StatisticsLast updated: August 22, 2026

Bayes' theorem is the rule that tells you how to update a belief once new evidence arrives: P(A|B) = P(B|A)·P(A) / P(B). Here P(A) is the prior probability (before the evidence) and P(A|B) is the posterior probability (after it). Expanding the denominator with the law of total probability turns the formula into P(B|A)·P(A) + P(B|Aʹ)·P(Aʹ), which can be evaluated on its own.

The fields are arranged for both general Bayes problems and medical screening tests: the prior probability corresponds to prevalence, P(B|A) to the sensitivity of the test, and P(B|Aʹ) to the false positive rate (1 − specificity). Alongside the posterior probability, the calculator returns the negative predictive value, both likelihood ratios, the prior and posterior odds, and a table showing how many true and false positives a hypothetical cohort of 100,000 people would produce.

%
The probability of the event before the evidence. In screening tests this is how common the disease is in the population.
%
The probability of seeing the evidence when the event is truly present: the rate at which the test is positive in people who have the condition.
The two are complements of each other: false positive rate = 1 − specificity.
%
The probability that the evidence is absent when the event is absent: the rate at which the test is negative in healthy people.
The imaginary population the results are converted into head counts for. The default is 100,000 people.

Bayes' Theorem

Bayes' theorem:      P(A|B) = P(B|A) · P(A) / P(B)
Expanded denominator: P(B) = P(B|A)·P(A) + P(B|Aʹ)·P(Aʹ)
Screening terms:     P(B|A) = sensitivity,  P(B|Aʹ) = 1 − specificity,  P(A) = prevalence
Negative result:     P(A|Bʹ) = [1 − P(B|A)]·P(A) / [1 − P(B)]
Negative predictive: NPV = P(Aʹ|Bʹ) = specificity · P(Aʹ) / [1 − P(B)]
Likelihood ratios:   LR⁺ = sensitivity / (1 − specificity),  LR⁻ = (1 − sensitivity) / specificity
Odds form:           posterior odds = prior odds × LR⁺,   prior odds = P(A) / [1 − P(A)]

Because the denominator is expanded with the law of total probability, the formula needs only three inputs: the prior probability, the sensitivity, and the false positive rate. The positive predictive value P(A|B) is not a constant of the test; it changes as prevalence changes.

How to Calculate

  1. Enter the prior probability as a percentage: in screening tests this is how common the condition is in the population.
  2. Enter the sensitivity (the rate of a positive result when the event is present); test documentation calls this 'sensitivity'.
  3. Choose how you want to enter the second conditional probability: as specificity or directly as the false positive rate.
  4. Change the cohort size if you need to; the default of 100,000 people keeps the results intuitive.
  5. Compare the posterior probability with the prior and look at how many times it changed; the change is where the information is.
  6. Read the true and false positive counts in the cohort table: that row shows how trustworthy a positive result really is.

Worked Examples

Screening for a rare disease

For a screening test with 1% prevalence, 99% sensitivity, and 95% specificity, P(B) = 0.99 × 0.01 + 0.05 × 0.99 = 0.0594 and the posterior probability stays at just 16.67%. In a cohort of 100,000 people, 5,940 receive a positive result, but only 990 of them truly have the disease and 4,950 are false positives. Among those who test negative, the probability of disease falls to 0.01%.

Posterior probability P(A|B): 16.67% · Prior probability P(A): 1.00% · Change from prior to posterior: 16.67-fold

The same test in a high-risk group

When prevalence rises to 30%, P(B) = 0.90 × 0.30 + 0.10 × 0.70 = 0.34 and the posterior probability climbs to 79.41%. Of the 34,000 positive results in a cohort of 100,000 people, 27,000 are true positives and 7,000 are false positives. With identical test characteristics, a higher prior probability alone makes a positive result far more trustworthy.

Posterior probability P(A|B): 79.41% · Prior probability P(A): 30.00% · Change from prior to posterior: 2.65-fold

A general Bayes problem — spam filter

20% of emails are spam; the filter flags 80% of the spam and 10% of the legitimate mail. Then P(B) = 0.80 × 0.20 + 0.10 × 0.80 = 0.24, and the probability that a flagged email really is spam is 0.16 / 0.24 = 66.67%. Out of 100,000 emails, 24,000 are flagged: 16,000 correctly and 8,000 as false positives.

Posterior probability P(A|B): 66.67% · Prior probability P(A): 20.00% · Change from prior to posterior: 3.33-fold

Frequently Asked Questions

What is Bayes' theorem used for?
It updates an existing belief (the prior probability) with new evidence and returns the result as a posterior probability. Diagnostic tests, spam filters, forensic evidence, and the naive Bayes classifier in machine learning all rest on this rule. The heart of the formula is that it reverses the direction of a conditional probability: if you know P(B|A), you can compute P(A|B).
Why does a highly sensitive test still produce false positives?
Because the positive predictive value depends not only on the test but also on prevalence. If a disease occurs in 1% of people, then out of 100,000 there are 1,000 who are ill and 99,000 who are not; even a false positive rate of 5% turns 4,950 healthy people positive, which dwarfs the 990 true positives. For rare events the base rate matters more than the test itself.
What is the difference between sensitivity, specificity, PPV, and NPV?
Sensitivity and specificity are fixed properties of the test: the rate of positive results in people with the condition and of negative results in people without it. PPV (positive predictive value) and NPV read in the other direction, from the result back to the condition, and they change with prevalence. The posterior probability in this calculator is the PPV; the negative predictive value is reported separately.
How is a likelihood ratio interpreted?
LR⁺ = sensitivity / (1 − specificity) tells you how many times a positive result multiplies the odds: values above 10 count as strong evidence and values below 2 as weak. LR⁻ = (1 − sensitivity) / specificity measures the ruling-out power of a negative result; below 0.1 is a strong rule-out. Thanks to the identity posterior odds = prior odds × LR, the calculation can even be done in your head.
What should I do if I do not know the prevalence?
Use a patient-specific clinical pre-test probability instead: an estimate based on age, symptoms, and risk factors. If that is unknown too, the right approach is a sensitivity analysis — repeat the calculation with several different priors and see how much the result moves. The dependence of the posterior on the prior is usually larger than the uncertainty in the estimate itself.
How do probabilities update across two consecutive tests?
The posterior probability of the first test becomes the prior probability of the second; you can enter the first result here and feed the output back in as a new prior. In odds form the update simply multiplies: posterior odds = prior odds × LR₁ × LR₂. This chaining is valid only if the tests are conditionally independent; for two tests measuring the same biological mechanism it is far too optimistic.
How do I reproduce these results in Excel or R?
In Excel a single cell is enough: =(sensitivity*prevalence)/(sensitivity*prevalence+(1-specificity)*(1-prevalence)). The same expression can be typed directly in R; the epi.tests() function of the epiR package also produces sensitivity, specificity, PPV, and NPV with confidence intervals from a 2×2 table. This calculator uses the same formulas and additionally shows the cohort breakdown.