Bayes’ theorem tells you how much a piece of evidence should change your belief. You start with a prior probability P(A) (how likely the hypothesis was before you looked) and multiply it by how much more likely the evidence is when the hypothesis is true than in general. The result is the posterior P(A | B).
Two versions are offered. If you know the overall probability of the evidence P(B), the theorem is a single division: for example, if 20% of days are rainy, 45% of mornings are cloudy and 60% of rainy days start cloudy, a cloudy morning raises the chance of rain to 0.6 × 0.2 ÷ 0.45 = 26.67%. More often you know the rate of the evidence with and without the hypothesis (a test’s sensitivity and its false-positive rate). The calculator then builds P(B) from the law of total probability.
The classic lesson is the rare-disease test: with 1% prevalence, 95% sensitivity and a 5% false-positive rate, a positive result means only about a 16% chance of disease, because healthy people vastly outnumber sick ones.
How to use the Bayes’ Theorem Calculator
- What do you know?
- Prior probability P(A)
- Probability of the evidence P(B)
- P(B | A), e.g. sensitivity
- P(B | not A), e.g. false-positive rate
Results update as you type, and everything is calculated in your browser.
How it works
The calculator finds P(B) (directly or from the two conditional rates), multiplies P(B | A) by P(A) to get the joint probability, and divides by P(B). It also reports the likelihood ratio (Bayes factor) and the prior and posterior odds, which give the same answer in odds form.
Worked example
A disease affects 1% of people. A test detects 95% of cases and gives a false positive for 5% of healthy people. P(positive) = 0.95 × 0.01 + 0.05 × 0.99 = 0.0095 + 0.0495 = 0.059. P(disease | positive) = 0.0095 ÷ 0.059 = 16.10%. In odds form: prior odds 1:99 = 0.0101, Bayes factor 0.95 ÷ 0.05 = 19, posterior odds 0.1919, which is 0.1919 ÷ 1.1919 = 16.10%.
Using the first method instead: P(rain) = 20%, P(cloudy) = 45% and P(cloudy | rain) = 60% give P(rain | cloudy) = 0.6 × 0.2 ÷ 0.45 = 26.67%.
How the prior changes the answer
| Prior P(A) | Posterior after a positive test (95% / 5%) |
|---|---|
| 0.1% | 1.87% |
| 1% | 16.10% |
| 10% | 67.86% |
| 50% | 95.00% |
Inputs explained
| Field | What to enter |
|---|---|
| What do you know? | Choose one: P(A), P(B) and P(B | A), P(A), P(B | A) and P(B | not A) (e.g. a test) |
| Prior probability P(A) | In % |
| Probability of the evidence P(B) | In % |
| P(B | A), e.g. sensitivity | In % |
| P(B | not A), e.g. false-positive rate | In % |
What each result means
- P(not A | B) = 100 – [Posterior P(A | B)]
- P(A | not B) = [Prior probability P(A)]×(100 – [P(B | A), e.g. sensitivity])÷(100 – [Total probability of the evidence P(B)])
- Bayes factor P(B | A) ÷ P(B | not A) = [P(B | A), e.g. sensitivity]÷[P(B | not A) used]
- Prior odds of A = [Prior probability P(A)]÷(100 – [Prior probability P(A)])
- Posterior odds of A = [Posterior P(A | B)]÷(100 – [Posterior P(A | B)])
Formula
P(A | B) = P(B | A) × P(A) ÷ P(B)
P(B) = P(B | A) × P(A) + P(B | not A) × (1 − P(A))
Posterior odds = prior odds × P(B | A) ÷ P(B | not A)
Worked example
Inputs: What do you know?: P(A), P(B | A) and P(B | not A) – e.g. a test; Prior probability P(A): 1 %; P(B | A) – e.g. sensitivity: 95 %; P(B | not A) – e.g. false-positive rate: 5 %.
Results: Posterior P(A | B) = 16.1017 %; Total probability of the evidence P(B) = 5.9 %; P(not A | B) = 83.8983 %; P(A | not B) = 0.0531 %; Bayes factor P(B | A) ÷ P(B | not A) = 19; Prior odds of A = 0.0101; Posterior odds of A = 0.1919.
Key terms
- Prior probability
- The probability of the hypothesis before the new evidence, P(A).
- Posterior probability
- The updated probability after the evidence, P(A | B).
- Likelihood
- How probable the evidence is if the hypothesis is true, P(B | A).
- Law of total probability
- P(B) = P(B | A)P(A) + P(B | not A)P(not A).
Frequently asked questions
What does Bayes’ theorem calculate?
The probability of a hypothesis after seeing evidence, P(A | B), from the probability before the evidence P(A) and how likely the evidence is under the hypothesis, P(B | A).
Why is the answer only about 16% for a 95% accurate test?
With 1% prevalence, 0.95% of people are true positives but 4.95% are false positives, so only 0.95 ÷ 5.9 ≈ 16.1% of positives are real.
What is the difference between P(A
B) and P(B | A)? | They are different questions. P(positive | disease) is the sensitivity; P(disease | positive) is the posterior. Confusing them is called the prosecutor’s fallacy.
When should I use Bayes’ theorem?
Whenever you need to reverse a conditional probability: diagnostic tests, spam filters, quality control, forensic evidence or updating forecasts with new data.
What is a Bayes factor?
The ratio P(B | A) ÷ P(B | not A). Multiplying the prior odds by it gives the posterior odds; a factor of 19 turns 1:99 odds into 19:99.
Can I chain several pieces of evidence?
Yes, if they are independent given A. Use the posterior from the first step as the prior for the next.
What happens if P(A) is 0% or 100%?
The posterior stays at 0% or 100%. No evidence can move a certainty, which is why priors should rarely be exactly 0 or 1.