Bayes' Theorem Calculator
Update a probability with new evidence: enter the prior P(A), P(B|A) and P(B|not A) to get the posterior P(A|B), such as a test's positive predictive value.
Bayes' Theorem Calculator
Background.
A test that catches 90% of true cases and raises a false alarm only 5% of the time sounds as if a positive result should be right about nine times in ten. If one in ten of the people tested actually has the condition, it is right two times in three. The missing ingredient is the base rate, and Bayes' theorem is the rule for putting it back in.
The theorem, published in 1763 after the death of the Reverend Thomas Bayes, says how to revise a probability when evidence arrives. You start with a prior, P(A): how likely the hypothesis was before you looked. Then you need two conditional probabilities: how often the evidence B turns up when A is true, and how often it turns up when A is false. The posterior, P(A|B), weighs the first against the second in proportion to how common A was to begin with.
That second conditional probability is the one people forget. When A is rare, the large group for whom A is false generates false alarms that can outnumber the true hits, even though each individual false alarm is unlikely. Medical screening, spam filters, fraud flags and forensic evidence all run into the same arithmetic.
The page handles the two-state case: A is either true or not, and B is either observed or not. All three values go in as probabilities between 0 and 1, not as percentages. It does not choose a prior for you, check that your two cases cover every possibility, or allow for evidence that is correlated with an earlier result. Deciding what to do about the posterior is a separate question.
What is bayes' theorem calculator?
Bayes' theorem expresses the probability of a hypothesis A given evidence B in terms of quantities that are usually easier to know: the prior probability of A, the probability of B when A is true, and the probability of B when A is false. In diagnostic testing those three are the prevalence, the sensitivity and the false-positive rate, and the posterior they produce is the positive predictive value.
The theorem is a two-line consequence of the definition of conditional probability. P(A|B) = P(A and B) ÷ P(B), and the joint probability P(A and B) can equally be written P(B|A) × P(A); substitute, expand P(B) into its two routes, true hits and false alarms, and the rule appears. As arithmetic it is uncontroversial. A helpful way to read it is as a count rather than a probability: imagine 1,000 cases, split them by the prior, apply each conditional probability to its own group, then ask what share of everyone showing the evidence actually has A. Research on risk communication has found that this natural-frequency framing makes base-rate problems much easier to get right than the same figures given as percentages.
How to use this calculator.
- Enter the Prior probability P(A) as a decimal: how likely A was before the evidence. For a screening test this is the prevalence in the group being tested, so 1 in 50 is 0.02.
- Enter P(B|A), the chance of seeing the evidence when A is true. For a diagnostic test this is the sensitivity, so 90% goes in as 0.9.
- Enter P(B|not A), the chance of the same evidence when A is false. For a test this is 1 minus the specificity, so a specificity of 95% goes in as 0.05.
- Read the posterior P(A|B) and multiply by 100 for a percentage. To update on a second, independent piece of evidence, enter this posterior as the new prior and run it again.
- If a test is described by its likelihood ratio rather than sensitivity and specificity, enter any pair with that ratio: a positive likelihood ratio of 18 can go in as 0.9 and 0.05, or as 0.18 and 0.01, and gives the same posterior.
The formula.
P(A|B) = P(B|A)·P(A) ÷ [P(B|A)·P(A) + P(B|not A)·P(not A)], where P(not A) = 1 − P(A). The numerator is the probability that A is true and the evidence appears. The denominator is the total probability of the evidence, true hits plus false alarms, which is why the prior and both conditional probabilities sit inside it. The posterior is therefore the share of all evidence-showing cases in which A really holds. An equivalent form uses odds: posterior odds = prior odds × P(B|A) ÷ P(B|not A), the final ratio being the likelihood ratio. When the prior is small the false-alarm term dominates the denominator, and the posterior stays modest even for strong evidence. The odds form also shows that only the ratio of the two conditional probabilities matters: 0.9 and 0.05 give exactly the same posterior as 0.18 and 0.01.
Which input moves the answer most depends on which term dominates the denominator. In the worked example, halving the false-positive rate from 0.05 to 0.025 lifts the posterior from 0.6667 to 0.8, while raising sensitivity from 0.9 to 0.99 nudges it only to 0.6875; with a modest prior, the false alarms from the large not-A group are the bigger term, so specificity is the lever. Two edge cases fall out of the algebra. A prior of exactly 0 or 1 never moves whatever the evidence, which is why a hypothesis that might need revising should never be given total certainty. And if the evidence has zero probability under both hypotheses, the denominator is zero and no posterior exists, so no result is returned.
The theorem is exact; its inputs rarely are. Sensitivity and specificity come from a study population, and a test can perform differently in people with earlier or milder disease than the ones it was validated on. Studies that confirm only the positives with a reference test can flatter the reported accuracy, the problem known as verification bias. Neither is visible in the arithmetic, so the posterior inherits whatever error the inputs carry.
A worked example.
Suppose 10% of the people tested have a condition, the test detects 90% of those who have it, and it wrongly flags 5% of those who do not. So P(A) = 0.1, P(B|A) = 0.9, P(B|not A) = 0.05 and P(not A) = 0.9. True positives: 0.9 × 0.1 = 0.09. False positives: 0.05 × 0.9 = 0.045. All positives: 0.09 + 0.045 = 0.135. The posterior is 0.09 ÷ 0.135 = 0.6667, two chances in three. Among 1,000 people tested that is 90 true positives out of 135 positive results. Lower the prior to 0.01 and the same test gives 0.009 ÷ 0.0585 ≈ 0.154, so most positives are false. Raise it to 0.5 and the posterior climbs to about 0.947. The same arithmetic runs a spam filter. Suppose half of incoming mail is spam and a particular phrase appears in 20% of spam but only 1% of legitimate mail. Then P(A) = 0.5, P(B|A) = 0.2 and P(B|not A) = 0.01: spam carrying the phrase is 0.2 × 0.5 = 0.1, legitimate mail carrying it 0.01 × 0.5 = 0.005, and the posterior is 0.1 ÷ 0.105 ≈ 0.9524. A phrase found in only a fifth of spam is still strong evidence, because its likelihood ratio is 0.2 ÷ 0.01 = 20; what counts is how much more often the evidence appears under A than under not-A, not how often it appears at all.
Frequently asked questions.
Why is the posterior so much lower than the test's accuracy?
How do I turn a test's specificity into P(B|not A)?
Can I update twice after two positive results?
Where should the prior probability come from?
What is the likelihood ratio, and how does it fit in?
What is the prosecutor's fallacy?
What does a negative test result tell me?
What if there are more than two possible explanations?
At what prior does a positive result become more likely true than false?
Is using Bayes' theorem the same as doing Bayesian statistics?
References& sources.
- [1]NIST/SEMATECH e-Handbook of Statistical Methods, Bayes' Theorem.
- [2]OpenStax, Introductory Statistics 2e, section 3.3, Two Basic Rules of Probability.
- [3]BIPM, The International System of Units (SI Brochure), 9th ed., version 3.01, coherent derived units and quantity equations.
- [4]NIST Special Publication 811, Guide for the Use of the International System of Units, 2008 edition.
- [5]Royal Statistical Society, Bayes theorem educational resources.
How this page was produced
- Published by
- Quanta Calculator
- Overseen by
- Daniel, Quanta Calculator Researcher
- Primary sources
- 5 cited below
- Method
- P(A|B) = P(B|A)P(A) / [P(B|A)P(A) + P(B|not A)P(not A)]
- Published
- Last verified
Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 1560 calculators remain free
- No billing is enabled