Bayes' Theorem Calculator
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.
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
- Enter the prior probability as a percentage: in screening tests this is how common the condition is in the population.
- Enter the sensitivity (the rate of a positive result when the event is present); test documentation calls this 'sensitivity'.
- Choose how you want to enter the second conditional probability: as specificity or directly as the false positive rate.
- Change the cohort size if you need to; the default of 100,000 people keeps the results intuitive.
- Compare the posterior probability with the prior and look at how many times it changed; the change is where the information is.
- 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