Bayes’ Theorem Calculator

Enter a prior probability and the chance of seeing the evidence with and without the hypothesis, and get the updated (posterior) probability P(A|B) — plus the odds-form breakdown.

#math#probability#statistics#bayes#conditional-probability
%

How likely A is before seeing any evidence — e.g. the base rate or prevalence.

%

For a diagnostic test, this is the sensitivity (true-positive rate).

%

For a diagnostic test, this is the false-positive rate (1 − specificity).

P(A | B) — posterior probability

7.764%

P(B) — total probability of the evidence
10.304%
P(not A | B)
92.236%
P(A | not B)
0.223%
Likelihood ratio P(B|A) ÷ P(B|not A)
8.3333
Prior odds of A
0.0101
Posterior odds of A
0.0842

Bayes' theorem updates the 1% prior to 7.764% once B is observed: P(A|B) = P(B|A)·P(A) ÷ P(B), where P(B) = 10.304%.

How to use this calculator

Fill in three probabilities, each as a percentage. First the prior P(A) — how likely the hypothesis is before any evidence, such as a disease’s prevalence or a defect rate. Then P(B|A), the chance of observing the evidence when A is true (for a diagnostic test, its sensitivity). Finally P(B|not A), the chance of observing the same evidence when A is false (the false-positive rate). The calculator returns the posterior P(A|B) — the probability of A once B has actually been observed — along with P(B), the complementary posteriors, the likelihood ratio, and the prior and posterior odds.

How the calculation works

Bayes’ theorem says P(A|B) = P(B|A)×P(A) ÷ P(B). The numerator is the probability that A is true and B occurs. The denominator P(B) is built with the law of total probability: evidence B can arrive down two roads — with A, contributing P(B|A)×P(A), or without it, contributing P(B|not A)×(1−P(A)) — and P(B) is their sum. The posterior is simply the share of P(B) that comes down the first road. The equivalent odds form is often quicker mentally: posterior odds = prior odds × likelihood ratio, where the likelihood ratio is P(B|A) ÷ P(B|not A) — how many times more often the evidence shows up when A is true than when it is false.

Worked example

The classic screening example (Eddy 1982, popularised by Gigerenzer): a condition affects 1% of those screened (prior 1%), the test catches 80% of true cases (P(B|A) = 80%) and false-alarms on 9.6% of healthy people (P(B|not A) = 9.6%). P(B) = 0.8×0.01 + 0.096×0.99 = 0.008 + 0.09504 = 0.10304, so P(A|B) = 0.008 ÷ 0.10304 ≈ 7.76%. Even after a positive result, the probability of the condition is under 8% — because true positives (0.8%) are swamped by false positives from the much larger healthy group (9.5%). Most people — including most physicians in published studies — guess 70–80%.

Frequently asked questions

What is Bayes’ theorem?

Bayes’ theorem is the rule for updating a probability when new evidence arrives: P(A|B) = P(B|A)×P(A) ÷ P(B). It converts the probability you started with (the prior) into the probability after seeing evidence B (the posterior). It follows directly from the definition of conditional probability and was published posthumously from Thomas Bayes’ notes in 1763.

Why are P(A|B) and P(B|A) different?

They condition on different things. P(B|A) asks "if A is true, how often do I see B?" while P(A|B) asks "given that I saw B, how likely is A?" A test can detect 80% of true cases (P(B|A) = 80%) while a positive result means only an 8% chance of the condition (P(A|B) = 8%) when the condition is rare. Swapping them is called the confusion of the inverse — in courtrooms, the prosecutor’s fallacy.

What is the base-rate fallacy?

Ignoring the prior. If a condition affects 1 person in 100 and a test false-alarms on ~10 healthy people in that same 100, then most positives are false positives no matter how good the test is at catching true cases. The base rate (prior) determines how many true and false positives exist to compare; neglecting it makes rare conditions look far more likely than they are after a positive result.

Why do I need P(B|not A)? I only know how accurate my test is when the condition is present.

Because the evidence can also occur when A is false, and Bayes’ theorem needs both routes to weigh them. P(B) = P(B|A)×P(A) + P(B|not A)×(1−P(A)) — without the second term you cannot tell how much of the evidence is false alarms. For a diagnostic test, P(B|not A) is 1 minus the specificity; for a smoke alarm, it is the rate of alarms with no fire.

What is the likelihood ratio and the odds form of Bayes’ theorem?

The likelihood ratio is P(B|A) ÷ P(B|not A) — how many times more probable the evidence is when A is true than when it is false. The odds form says posterior odds = prior odds × likelihood ratio. With the default inputs the LR is 0.8 ÷ 0.096 ≈ 8.33: prior odds of 1:99 become 8.33:99 ≈ 0.084, i.e. a posterior of about 7.76%. Evidence with an LR of 1 is uninformative — the posterior equals the prior.

What happens if the prior is 0% or 100%?

The posterior stays put. A prior of 0 means A is impossible, and no evidence can rescue it — P(A|B) is 0 whatever the test says. A prior of 100% likewise stays at 100%. This is why statisticians caution against priors of exactly 0 or 1 (sometimes called Cromwell’s rule): reserve them for genuine logical impossibilities, not just strong beliefs.