Bayes' Theorem Calculator
Bayes' theorem updates a prior belief once you observe new evidence. Choose what you want to find, enter the three known values, and get the posterior probability, a step-by-step derivation, a confusion matrix for any population size, and a chart showing how the result changes as the prior shifts.
Formula
Worked example
A disease affects 1% of people (prior P(A) = 0.01). A test is 90% sensitive (P(B|A) = 0.90) with a 9% false-positive rate (P(B|notA) = 0.09). Then P(B) = 0.90 x 0.01 + 0.09 x 0.99 = 0.0981, so P(A|B) = 0.009 / 0.0981 = 0.0917, about 9.2%. In 1,000 people: 9 true positives, 89.1 false positives - so only 1 in 11 positive results is a real case.
What Bayes' theorem does
Bayes' theorem is the mathematical rule for updating a prior belief when new evidence arrives. You start with a prior probability - how likely a hypothesis A is before you look at any data - and combine it with two conditional likelihoods: P(B|A), the probability of seeing the evidence when A is true (sensitivity), and P(B|notA), the probability of seeing the evidence when A is false (the false-positive rate, equal to 1 minus the specificity). The result is the posterior probability P(A|B): what you should believe after the evidence. The theorem flips a conditional you can measure into the one you actually care about, and that single equation underpins medical diagnosis, spam filtering, machine learning classifiers, and rational decision-making under uncertainty.
Four things you can solve for
Most tools only solve for P(A|B), but Bayes' theorem is an equation with four variables and you can rearrange it to find any one of them. Use the 'Solve for' selector to switch modes. Solving for P(B|A) tells you what sensitivity a test would need to achieve a target posterior - useful when designing a screening program. Solving for P(A) reverse-engineers the prior prevalence from a known posterior and test parameters - useful in epidemiology when you know the positive predictive value but want to infer base rate. Solving for P(B) gives the marginal likelihood, the overall proportion of cases that test positive, which is the denominator that anchors the whole calculation.
The confusion matrix and natural frequencies
Abstract probabilities are hard to reason about. A confusion matrix translates them into concrete counts for a population of any size. Set the population to 1,000 and you can see directly how many people fall into each cell: true positives (condition present, test positive), false positives (condition absent, test positive), false negatives (condition present, test negative), and true negatives (condition absent, test negative). The positive predictive value (PPV) is the fraction of all positives that are true, which is exactly the posterior P(A|B). The negative predictive value (NPV) is the fraction of all negatives that are true negatives. Natural-frequency reasoning - 9 true positives versus 89 false positives in 1,000 people - is cognitively much easier than working with decimals and it consistently improves intuition about base-rate effects.
The base-rate trap and the likelihood ratio
The most famous lesson of Bayes is that base rates dominate. If a condition is rare, a positive result from even a very accurate test is more likely to be a false alarm than a true case. In the classic example a 90% sensitive, 91% specific test on a 1% disease yields only a 9% chance of actually having the disease after a positive result - about 9 true positives versus 89 false positives per 1,000 people. A complementary summary is the positive likelihood ratio (LR+), equal to sensitivity divided by the false-positive rate. An LR+ above 10 is considered very strong evidence (typically pushing a 10% prior to over 50%), while an LR+ below 2 is weak. The calculator reports LR+ alongside the posterior so you can judge the evidence strength independently of the prior.
How the chart helps intuition
The chart in the posterior-solve mode plots P(A|B) against every possible prior from 0% to 99%, keeping the sensitivity and false-positive rate fixed at your current inputs. The diagonal line is the prior itself (no evidence effect). When the two lines are far apart the test is highly informative; when they are close the evidence barely moves belief. The chart makes it immediately visible why raising the prior from 1% to 10% dramatically changes the posterior even with identical test performance, and why a test with a high false-positive rate produces a nearly flat curve for small priors.
How the posterior and likelihood ratio depend on the prior
| Prior P(A) | P(B) total | Posterior P(A|B) | True pos. / 1,000 | False pos. / 1,000 | PPV |
|---|---|---|---|---|---|
| 0.1% | 9.09% | 0.99% | 0.9 | 89.9 | 0.99% |
| 1% | 9.81% | 9.17% | 9.0 | 89.1 | 9.17% |
| 5% | 13.05% | 34.48% | 45.0 | 85.5 | 34.48% |
| 10% | 17.10% | 52.63% | 90.0 | 81.0 | 52.63% |
| 25% | 29.25% | 76.92% | 225.0 | 67.5 | 76.92% |
| 50% | 49.50% | 90.91% | 450.0 | 45.0 | 90.91% |
Same 90% sensitivity (P(B|A)) and 9% false-positive rate (P(B|notA)), varying the base rate P(A). LR+ = 10.
Frequently asked questions
What is the difference between P(A|B) and P(B|A)?
P(B|A) is the probability of seeing the evidence B given that A is true - for a medical test this is the sensitivity, known from validation studies. P(A|B) is the reverse: the probability that A is true given you observed B. Bayes' theorem converts the measurable P(B|A) into the decision-relevant P(A|B). Confusing the two is called the prosecutor's fallacy and is a common reasoning error in medical, legal, and scientific contexts.
Why can a positive test still mean I probably do not have the disease?
When a condition is rare, the people who test positive are mostly false positives drawn from the large healthy population. Even a 90% sensitive, 91% specific test on a 1% disease yields only about 9% chance of disease after a positive result - about 9 true positives versus 89 false positives per 1,000. This is why doctors confirm with a second, more specific test and why screening programs work better for higher-risk subgroups where the prior is larger.
What should I enter for the prior probability?
The prior P(A) is your best estimate of how likely the hypothesis is before seeing the evidence. For a disease use the prevalence in the relevant population; for a general belief use your honest starting credence. The result is only as good as this input, so use the most realistic base rate you can find. A 50% default is almost always wrong and will inflate the posterior unrealistically.
What is the positive likelihood ratio and why does it matter?
The positive likelihood ratio LR+ equals sensitivity divided by the false-positive rate (1 minus specificity). It summarises a test's discriminating power independently of the prior. An LR+ of 10 means a positive result is 10 times more likely in people who have the condition than in people who do not. Pre-test odds multiplied by LR+ give post-test odds, which is an alternative way to apply Bayes without computing P(B). Values above 10 are considered strong, 2-10 moderate, and below 2 weak.
What is the confusion matrix and how do PPV and NPV relate to Bayes?
The confusion matrix shows the four possible outcomes in a population: true positives, false positives, false negatives, and true negatives. The positive predictive value (PPV = TP / (TP + FP)) is exactly the posterior probability P(A|B) - the probability that a positive result is a true positive. The negative predictive value (NPV = TN / (TN + FN)) is the probability that a negative result is a true negative. Both depend on the prior (prevalence) as well as test sensitivity and specificity, which is why PPV and NPV quoted for a test only apply at the prevalence where they were measured.
Can I solve for the prior or the sensitivity instead of the posterior?
Yes. Use the 'Solve for' selector to choose which variable to calculate. Solving for P(B|A) tells you what sensitivity would be needed to achieve a desired posterior given a known prior and false-positive rate. Solving for P(A) reverse-engineers the prior that would produce a given posterior - useful in epidemiology when you know PPV from a study and want to infer prevalence. Solving for P(B) computes the total evidence probability, which is the denominator of Bayes' theorem.