Audited 31 Jul 2026·Last updated 28 Oct 2026·5 citations·Tier 1·0 uses

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

Posterior probability P(A|B)
0.6667
The updated probability that A is true given that B was observed, a decimal between 0 and 1; when B is a positive test result this is the positive predictive value, and multiplying by 100 gives a percentage.
Model scope
Two-state Bayes update with supplied conditional probabilities; it does not establish that events are exhaustive, select a prior, account for dependence or verification bias, or interpret a medical, legal, or operational decision.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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)]

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.

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.

true Positive Probability0.9
false Positive Probability0.05
prior Probability0.1

Frequently asked questions.

Why is the posterior so much lower than the test's accuracy?
Because accuracy describes the test, while the posterior describes the people who tested positive. Of 1,000 people with a 10% prevalence, the 900 without the condition produce 45 false positives at a 5% false-positive rate, against 90 true positives. A third of the positives are therefore false, however good the test sounds.
How do I turn a test's specificity into P(B|not A)?
Subtract it from 1. Specificity is the chance of a negative result when A is false, so the chance of a positive is the remainder: 98% specificity means 0.02. Entering the specificity itself by mistake wrecks the answer; in the example, 0.98 instead of 0.05 would give a posterior of about 0.093.
Can I update twice after two positive results?
Yes, if the second result is independent of the first given whether A is true. Feed the posterior back in as the prior: after the example's 2/3, a second identical positive raises it to about 0.973. Repeating the same test often repeats the same error, though, so real gains are usually smaller.
Where should the prior probability come from?
From the base rate in the group the evidence applies to: disease prevalence among those being tested, the share of spam in an inbox, the fraud rate in a set of transactions. The same test gives very different posteriors in population screening and in a clinic seeing people with symptoms, because the priors differ. With the example test, a prior of 0.01 in a screening programme gives a posterior of about 0.1538, while a prior of 0.3 in a symptomatic clinic gives about 0.8852.
What is the likelihood ratio, and how does it fit in?
It is P(B|A) divided by P(B|not A), the factor by which the evidence multiplies the odds. In the example it is 0.9 ÷ 0.05 = 18. Prior odds of 1 to 9 become 18 to 9, or 2 to 1, which is the same posterior of 2/3.
What is the prosecutor's fallacy?
Treating P(B|A) as if it were P(A|B). If a forensic match would occur by chance in one innocent person in a million, that is P(evidence | innocent), not the probability the suspect is innocent. In a large enough population several innocent people would match, and only the prior can say how many. Suppose the true source is known to live in a city of 2 million and nothing else points at anyone: about 2 innocent residents would be expected to match as well, so on the match alone a matching person is the source with a probability nearer one in three than a million to one.
What does a negative test result tell me?
Treat the negative result as the evidence B. P(B|A) becomes 1 minus the sensitivity, 0.1 in the example, and P(B|not A) becomes the specificity, 0.95. With the same 0.1 prior the posterior is about 0.0116, so after a negative test the chance of having the condition falls from 10% to roughly 1.2%, a negative predictive value of about 98.8%.
What if there are more than two possible explanations?
Multiply each hypothesis's prior by the probability of the evidence under it, then divide each product by their sum. To get one of them from this page, enter the other hypotheses' likelihoods, weighted by their priors, as P(B|not A). With priors 0.5, 0.3 and 0.2 and likelihoods 0.1, 0.4 and 0.8, that is (0.3 × 0.4 + 0.2 × 0.8) ÷ 0.5 = 0.56, and the first hypothesis's posterior is about 0.152.
At what prior does a positive result become more likely true than false?
When the prior odds equal the reciprocal of the likelihood ratio, the posterior is exactly one half. For the example test the likelihood ratio is 18, so the break-even prior is 1 ÷ (1 + 18) ≈ 0.0526, about 1 in 19. In any group where the condition is rarer than that, most positives will be false, which is the arithmetic behind confirming a screening positive with a second, more specific test before acting on it.
Is using Bayes' theorem the same as doing Bayesian statistics?
Not quite. The theorem is a rule of probability that every school of statistics accepts, and applied to known frequencies such as prevalence and test accuracy it raises no dispute. Bayesian statistics goes further, placing prior distributions on unknown quantities such as a treatment effect and updating them with data, and the long-running debate is about how those priors should be chosen. A single update with probabilities you supply, as here, is the uncontroversial kind.

How this page was produced

Published by
Quanta Calculator
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
Coming soon