Bayes' Theorem Calculator (Posterior Probability)
Bayes' theorem updates a prior belief with new evidence: it turns the probability of a positive test given a condition into the probability of the condition given a positive test. This Bayes' theorem calculator works from the prior probability, the true-positive rate and the false-positive rate, and shows why rare events give many false alarms.
How to use the Bayes’ theorem calculator
Enter the prior probability of A, the probability of the evidence B when A is true (true-positive rate or sensitivity) and when A is false (false-positive rate, 1 − specificity). The calculator returns the overall probability of seeing B, the posterior probability of A given B, and the probability of A despite a negative result.
Bayes’ theorem formula
P(A|B) = P(B|A) × P(A) ÷ P(B)
P(B) = P(B|A) × P(A) + P(B|¬A) × (1 − P(A))
Example
A condition affects 1% of people. A test detects it 95% of the time and gives a false positive 5% of the time:
- P(B) = 0.95 × 0.01 + 0.05 × 0.99 = 5.90%
- P(A|B) = 0.95 × 0.01 ÷ 0.0590 = 16.10%
- P(A|not B) = 0.05 × 0.01 ÷ 0.9410 = 0.0531%
Out of 10,000 people: 95 true positives and 495 false positives — so only about 1 in 6 positives has the condition.
Posterior probability after one positive result
| Prior P(A) | Test 95% / 5% | Test 99% / 1% |
|---|---|---|
| 0.1% | 1.9% | 9.0% |
| 0.5% | 8.7% | 33.2% |
| 1% | 16.1% | 50.0% |
| 2% | 27.9% | 66.9% |
| 5% | 50.0% | 83.9% |
| 10% | 67.9% | 91.7% |
| 20% | 82.6% | 96.1% |
| 50% | 95.0% | 99.0% |
Notes
- A second, independent positive test uses the first posterior as the new prior and raises the probability sharply.
- The same reasoning applies to alarm systems: a sensitive alarm for a rare fault produces mostly nuisance trips.
Frequently asked questions
What is Bayes' theorem?
P(A|B) = P(B|A) × P(A) ÷ P(B), where P(B) = P(B|A)P(A) + P(B|not A)(1 − P(A)). It gives the probability of A after observing B.
Why is a positive result from a 95% accurate test often wrong?
When the condition is rare, false positives from the large healthy group outnumber the true positives. With 1% prevalence and a 5% false-positive rate, only about 16% of positives are real.
What are prior and posterior probabilities?
The prior P(A) is what you believe before the evidence; the posterior P(A|B) is the updated probability after it. Today's posterior can be the prior for the next test.
What is P(A | not B)?
The chance that A is true even though the evidence was negative — the false-negative risk. It depends on the sensitivity and the prior.