Bayes Theorem Calculator
Enter how common event A is, how often B shows up when A is true, and how often B shows up when A is false. The calculator returns the updated probability of A after you observe B, and after you do not.
Created by the Reeliy Editorial Team. Last updated: Oct 19, 2026
What Bayes' theorem says
Bayes' theorem tells you how to update a probability when you learn something new. You start with a prior: how likely an event A was before you saw any evidence. You then observe evidence B, and the theorem turns the prior into a posterior, the probability of A given B.
The idea is named after Thomas Bayes, whose essay on the subject was published after his death in 1763. It is the foundation of medical test interpretation, spam filtering, forensic statistics and a large part of modern machine learning.
The formula
P(A|B) = P(B|A) · P(A) ÷ P(B)
The denominator P(B) is the overall chance of seeing B, whether or not A is true. By splitting the world into "A" and "not A" it can be written out in full:
P(A|B) = P(B|A) · P(A) ÷ [ P(B|A) · P(A) + P(B|¬A) · (1 − P(A)) ]
The same expression with B replaced by "not B" gives the second result, the probability of A even though B was not observed. The two outputs of this tool are exactly these two quantities.
A handy equivalent form uses odds. The posterior odds of A equal the prior odds multiplied by the likelihood ratio P(B|A) ÷ P(B|¬A). A strong test is simply one with a large likelihood ratio.
How to use the calculator
- Input as: choose percentages (5%) or proportions (0.05) and use the same style in all three boxes.
- Probability of / based on (optional): name the two events, for example cancer and positive test. The labels and the result lines then read P(cancer|positive test) instead of P(A|B).
- P(A): the prior, such as the prevalence of a condition or the share of mail that is spam.
- P(B|A): the chance of B when A is true. For a medical test this is the sensitivity.
- P(B|¬A): the chance of B when A is false. For a test this is the false positive rate, which equals 100% minus the specificity. If a test is 95% specific, enter 5%, not 95%.
All three numbers must lie strictly between 0 and 100% (0 and 1). A value of exactly 0 or 100% means certainty, and the formula cannot be applied in a meaningful way, so the calculator asks you to revise the input.
Worked example: a screening test
A condition affects 1% of a population. A screening test is positive for 90% of people who have it and, wrongly, for 9% of people who do not. You test positive. How worried should you be?
Put the numbers in: P(A) = 0.01, P(B|A) = 0.90, P(B|¬A) = 0.09.
P(A|B) = 0.90 × 0.01 ÷ (0.90 × 0.01 + 0.09 × 0.99) = 0.009 ÷ 0.0981 ≈ 9.17%
Only about 9 in 100 positive results are real. A natural-frequency check makes this intuitive: in 10,000 people, 100 have the condition and 90 of them test positive, while 9,900 are healthy and 891 of them test positive anyway. The positives are 90 true against 891 false, and 90 ÷ 981 ≈ 9.17%.
The second output answers the opposite question. A negative result leaves P(A|¬B) = 0.10 × 0.01 ÷ (0.10 × 0.01 + 0.91 × 0.99) ≈ 0.11%, so a negative test is very reassuring.
Why the prior matters: the base rate fallacy
People often judge a positive result by the accuracy of the test alone and forget how rare the condition is. Ignoring the prior is called the base rate fallacy. The same test, with 90% sensitivity and a 9% false positive rate (a likelihood ratio of 10), gives very different posteriors depending on the prior:
| Prior P(A) | P(A | positive) | P(A | negative) |
|---|---|---|
| 0.1% | 0.99% | 0.011% |
| 1% | 9.17% | 0.11% |
| 10% | 52.63% | 1.21% |
| 50% | 90.91% | 9.90% |
| 90% | 98.90% | 49.72% |
A positive result is strong evidence only when the prior is not tiny. For a rare condition, most positives come from the large healthy group, even with a good test.
More applications
Spam filtering. Suppose 40% of incoming mail is spam, the word "free" appears in 60% of spam and in 5% of legitimate mail. For a message containing "free": P(spam|free) = 0.60 × 0.40 ÷ (0.60 × 0.40 + 0.05 × 0.60) = 0.24 ÷ 0.27 ≈ 88.9%. A message without the word has a 21.9% chance of being spam. Real filters combine many words with this same rule, which is the idea behind naive Bayes.
Drug testing. If 5% of an employee group uses a substance, and a test flags 95% of users and 3% of non-users, a positive result means the person is a user with probability 0.0475 ÷ 0.076 = 62.5%, so a single positive is far from conclusive.
Quality assurance. A line produces 2% defective parts, and an inspection catches 98% of defects but also rejects 1% of good parts. The share of rejected parts that are truly defective is 0.0196 ÷ (0.0196 + 0.0098) ≈ 66.7%.
Assumptions and limits
- The prior must describe the population the person actually comes from. A prevalence taken from the general public is the wrong prior for someone who already has symptoms.
- The tool handles one piece of binary evidence. To combine several tests, feed the posterior of the first in as the prior of the next, which is only valid if the tests are independent given A.
- Sensitivity and the false positive rate are themselves estimates, so the posterior inherits their uncertainty.
- Probabilities, not certainties: a posterior of 9% does not mean the person is healthy, only that illness is less likely than not.
For related counting problems, see the combination calculator and the binomial distribution calculator; to compare risks in two groups, the relative risk calculator and the odds ratio calculator.
Frequently asked questions
What is the difference between P(A|B) and P(B|A)?
P(B|A) is how often the evidence appears when A is true, such as a test's sensitivity. P(A|B) is how likely A is once you have seen the evidence. They can differ enormously, and Bayes' theorem is the bridge between them.
What should I enter for specificity?
The third box takes P(B|¬A), the false positive rate. If you know the specificity, subtract it from 100%: a specificity of 95% means you enter 5%.
Why is my positive probability so low when the test is accurate?
Because the condition is rare. Even a small false positive rate, applied to the large group of people without the condition, produces more false alarms than the small group with it produces true positives.
Why does the calculator reject 0% and 100%?
If a prior or a likelihood is exactly 0 or 1 the evidence either cannot matter or leads to a division by zero. Use values such as 0.01% or 99.99% to express near-certainty.
References
- Bayes T. An essay towards solving a problem in the doctrine of chances. Philosophical Transactions of the Royal Society of London. 1763;53:370-418.
- Gigerenzer G, Hoffrage U. How to improve Bayesian reasoning without instruction: frequency formats. Psychological Review. 1995;102(4):684-704.
- Kahneman D, Tversky A. On the psychology of prediction. Psychological Review. 1973;80(4):237-251.
Cite this calculator and page
If you use this page in your work, you can cite it as:
Reeliy Editorial Team. (2026). Bayes Theorem Calculator. Reeliy. https://reeliy.com/calculators/bayes-theorem-calculator“Bayes Theorem Calculator.” Reeliy, 2026, https://reeliy.com/calculators/bayes-theorem-calculator.