Bayes Theorem Calculator
Bayes Theorem Calculator
Update a probability with new evidence. Enter the prior and how likely the evidence is if you are right and if you are wrong, and get the new probability, or work a screening test from prevalence, sensitivity and specificity, use the odds form, or chain several pieces of evidence.
1,000 people
Probability after the evidence, against the prior
P(A | B) = P(A) × P(B | A) ÷ P(B), where P(B) = P(A) × P(B | A) + P(not A) × P(B | not A). For a test, PPV = prevalence × sensitivity ÷ (prevalence × sensitivity + (1 − prevalence) × (1 − specificity)). Odds form: posterior odds = prior odds × likelihood ratio, with LR+ = sensitivity ÷ (1 − specificity) and LR− = (1 − sensitivity) ÷ specificity. Several pieces of evidence are multiplied in turn, which assumes they are independent. A plain number below 1 is read as a decimal and above 1 as a percentage; type 1% or 100% for a bare one. The tool gives general information, not medical advice; interpret test results with a clinician. The CSV, image and printed report contain only the values you entered.
How to use this tool
Choose what you know from the Work out menu. The default takes the prior P(A), how likely the evidence B is when A is true, P(B | A), and how likely it is when A is false, P(B | not A). The screening test mode takes prevalence, sensitivity and specificity and adds a table of natural frequencies. Other modes cover a known overall P(B), the odds form, up to three pieces of evidence in a row, and reference tables. Probabilities can be percentages or decimals, and the note under each box shows how it was read.
The input people most often get wrong is the false positive side. P(B | not A) is the false positive rate, and specificity is one minus it, so a test that gives false alarms for 9.6% of healthy people has a specificity of 90.4%, not 9.6%. A bare 1 could mean 1% or 100%, so type 1% or 100%.
What the calculation is doing
Bayes theorem is P(A | B) = P(A) × P(B | A) ÷ P(B), where P(B) = P(A) × P(B | A) + P(not A) × P(B | not A) is the chance of seeing B whether or not A is true. The answer is the share of all the ways B can happen that run through A. For a test, the positive predictive value is prevalence × sensitivity ÷ (prevalence × sensitivity + (1 − prevalence) × (1 − specificity)).
The odds form does the same job in one multiplication: posterior odds equal prior odds times the likelihood ratio, with LR+ = sensitivity ÷ (1 − specificity) and LR− = (1 − sensitivity) ÷ specificity. A prior of 1% is odds of 1 to 99, and an LR+ of 8.33 makes them 1 to 11.9, which is 7.76%.
For several pieces of evidence, each posterior becomes the next prior, which is the same as multiplying the likelihood ratios in any order. That is valid only when the pieces are independent given the true state.
The natural frequency table turns probabilities into counts of people, 1,000 by default and up to 1,000,000 for rare conditions, rounded so the four cells add to the group size. Values from rounded counts can differ slightly from the exact ones, such as 7.77% against 7.76%.

The base rate, and why counting people works
Bayes theorem is a rule for changing your mind: start with what you believed, weigh how much more likely the evidence is if you are right than if you are wrong, and end with a new belief. Gigerenzer and Hoffrage (1995, Psychological Review 102) pose a mammography problem: 1% of women at forty in routine screening have breast cancer, 80% of those get a positive mammogram, and 9.6% of those without cancer do too. The correct probability of cancer after a positive result is 7.8%, and they report that Eddy (1982) found 95 out of 100 physicians estimated 70% to 80%.
The natural frequency trick removes the confusion. Picture 1,000 women. Ten have cancer and 8 of them test positive. Of the 990 without cancer, 95 test positive. That is 103 positives, 8 of them real, and 8 ÷ 103 is about 7.8%. The base rate is already in the counts: healthy women outnumber the others 99 to 1, so a small false positive rate still produces far more false alarms than true positives. In their experiments, frequency formats elicited Bayesian algorithms in 46% of solutions in the standard menu, against 16% for probability formats.
Gigerenzer's 2010 conference paper set gynecologists a similar problem, with 1% prevalence, 90% sensitivity and a 9% false positive rate, and reports that 60% of them thought the chance was 81% or 90%. The tool gives 9.17%, from 9 true positives among 98 positives.
The same 80% sensitivity and 90.4% specificity give 0.827% at 0.1% prevalence, 7.76% at 1%, 48.1% at 10% and 89.3% at 50%, so the test did not change but the answer did. It is not only medical. A factory scanner that flags 90% of defective parts and 5% of good ones, on a batch that is 2% defective, flags 18 defective and 49 good parts per 1,000, so only 26.9% of flags are real. These inspection numbers are illustrative.
Confusing P(A | B) with P(B | A)
Sensitivity is P(positive | condition), the chance a person who has it tests positive. The positive predictive value is P(condition | positive), the chance a person who tested positive has it. They differ, 80% and 7.76% in the mammography example, and only Bayes theorem connects them. Sensitivity and specificity describe the test, while predictive values describe a person holding a result, so they also depend on the base rate.
The same slip in a courtroom is the prosecutor's fallacy. In October 2001 the Royal Statistical Society issued a statement on the Sally Clark case, where a figure of 1 in 73 million had been given for two infant deaths both being sudden infant death syndrome (SIDS). The Society said the figure "has no statistical basis", because squaring one family's probability is valid only if SIDS cases arise independently within families, "an assumption that would need to be justified empirically". Reading the figure as the chance the deaths were accidental, it added, is a serious error of logic. The right comparison sets the likelihood of the evidence under each explanation against the other, which is what the odds form does.
Chaining evidence, and where independence breaks
Sequential updating multiplies likelihood ratios. Start at 1% and apply a positive result from a test with 90% sensitivity and 95% specificity, an LR+ of 18, and the probability moves to 15.4%. A second independent positive moves it to 76.6%, because the odds rise by a factor of 324.
Independence is the weak point. A second positive from the same blood sample, scanner or biological quirk usually shares the first one's mistakes. If it simply repeats them, the second positive adds nothing and the answer stays at 15.4%, not 76.6%. Treat the chained answer as an upper limit when false alarms tend to repeat.
What the tool cannot know
A sensitivity of 80% came from some study of some group of people, and the tool takes it as exact for whoever you ask about. Real error rates vary with the population, the setting and the cutoff, and the base rate that matters is the one for a person like the one in front of you.
Try a low and a high value to see how far the answer moves. This page gives general information, not medical advice, and test results should be interpreted with a clinician who knows the person and the test.
Positive predictive value by prevalence, specificity and sensitivity
Both tables come from the calculator engine. In the first, sensitivity is held at 90% and each column is a specificity. Read down a column to see prevalence at work.
| Prevalence | Specificity 90% | Specificity 95% | Specificity 99% | Specificity 99.9% |
|---|---|---|---|---|
| 0.1% | 0.893% | 1.77% | 8.26% | 47.4% |
| 1% | 8.33% | 15.4% | 47.6% | 90.1% |
| 5% | 32.1% | 48.6% | 82.6% | 97.9% |
| 10% | 50% | 66.7% | 90.9% | 99.01% |
| 30% | 79.4% | 88.5% | 97.5% | 99.74% |
| 50% | 90% | 94.7% | 98.9% | 99.89% |
A test with 90% sensitivity and 95% specificity needs a prevalence of 5.26% before a positive result is right half the time. At 0.1% prevalence even 99.9% specificity leaves the positive predictive value below 50%, at 47.4%.
In the second table specificity is held at 95% and each column is a sensitivity.
| Prevalence | Sensitivity 50% | Sensitivity 70% | Sensitivity 90% | Sensitivity 99% |
|---|---|---|---|---|
| 0.1% | 0.991% | 1.38% | 1.77% | 1.94% |
| 1% | 9.17% | 12.4% | 15.4% | 16.7% |
| 5% | 34.5% | 42.4% | 48.6% | 51% |
| 10% | 52.6% | 60.9% | 66.7% | 68.7% |
| 30% | 81.1% | 85.7% | 88.5% | 89.5% |
| 50% | 90.9% | 93.3% | 94.7% | 95.2% |
At low prevalence, specificity matters far more than sensitivity for the positive predictive value. At 1% prevalence, lifting sensitivity from 50% to 99% moves it from 9.17% to 16.7%, while lifting specificity from 90% to 99.9% moves it from 8.33% to 90.1%.
A worked example you can check on paper
The calculator opens on the mammography numbers: P(A) = 0.01, P(B | A) = 0.8 and P(B | not A) = 0.096. Then 0.01 × 0.8 = 0.008 for A and B, and 0.99 × 0.096 = 0.09504 for not A and B. So P(B) = 0.10304 and P(A | B) = 0.008 ÷ 0.10304 = 0.0776, which is 7.76%, a lift of 7.76 times the prior.
The odds route agrees. Prior odds are 1 to 99 and LR+ = 0.8 ÷ 0.096 = 8.333, so posterior odds are 8.333 ÷ 99 = 0.08418, and 0.08418 ÷ (1 + 0.08418) = 0.0776. In counts, 8 ÷ 103 = 7.77%, which differs only because 95.04 false positives were rounded to 95 whole people.
Mistakes that catch people out
Reading sensitivity as the chance a positive is real. A sensitivity of 80% says 80% of people with the condition test positive. Use the positive predictive value for the share of positives that have it.
Using one accuracy figure for both errors. A test can catch 99% of cases and still raise false alarms for 10% of healthy people. Find sensitivity and specificity separately.
Picking the wrong base rate. Prevalence in a routine screening group is not prevalence among people with symptoms. Enter the one for people like the person in question.
Confusing the false positive rate with the share of positives that are false. The mammography test has a false positive rate of 9.6%, yet 92.2% of its positives at 1% prevalence are false. The second figure is 1 − PPV and moves with prevalence.
Multiplying evidence that is not independent. Two tests that share a cause of error do not double the information, and if the errors repeat, the chained answer is too high.
Popular calculations
Each link opens the calculator with those numbers filled in and shows the probability of A after the evidence.
Published worked examples
The same test at different prevalences
Rare conditions and very good tests
Spam, inspection and fraud with illustrative numbers
Odds form and likelihood ratios
Two or three pieces of evidence
When P(B) is known directly
How this was checked
A separate program compared the engine with brute force. For 5,000 random triples of P(A), P(B | A) and P(B | not A), it enumerated the four joint probabilities and computed the posterior from them; the largest relative difference was 2.2 × 10⁻¹⁶. It also built an exact population of 1,000,000 people with integer counts, using big integers, for 6,000 combinations of prior and likelihoods; the largest difference was 4.4 × 10⁻¹⁶. The four natural frequency cells added up to the group size in all 6,000 random cases.
The odds form and the probability form agreed to 4.4 × 10⁻¹⁶ over 6,000 random inputs. Sequential updating one step at a time matched one step with the product of the likelihood ratios, in either order, over 4,000 random cases. The positive predictive value never fell and the negative predictive value never rose as prevalence went from 0.1% to 99.9%, across 599,400 points. Prevalence, sensitivity or specificity of 0% and 100%, and P(B) = 0, give the expected value or a clear "not defined" message.
Published examples were reproduced. Gigerenzer and Hoffrage's mammography problem gives 0.0776 against their .078, with counts of 8 and 95. Gigerenzer's 2010 gynecologist problem gives 9 true and 89 false positives, as printed. OpenStax Principles of Data Science, section 3.4, Example 3.21 gives 0.1339 against 0.134. David Lippman's Math in Society, section 12.4, Example 19 gives 0.0196 against 1/51 and Example 20 gives 0.6475 against 180/278. The Wikipedia bowel cancer example (20, 180, 10 and 1,820 people) gives 10%, 99.45%, LR+ 7.4 and post test odds of 0.111, all as printed, and its drug test gives 22.95% against "approximately 23%".
Common questions
What does Bayes theorem say in one sentence?
The probability of A after seeing B is the prior probability of A, times how likely B is if A is true, divided by how likely B is overall.
Why is a positive result from a 99% accurate test often wrong?
Because 99% right for each group is a different claim from a positive result being right 99% of the time. If 0.3% of people use a drug and the test is 99% sensitive and 99% specific, a positive is a true positive only about 23% of the time, the example worked in Wikipedia's article on Bayes theorem.
How do I get the positive predictive value from sensitivity, specificity and prevalence?
Multiply prevalence by sensitivity for the true positives, multiply the rest of the population by 1 − specificity for the false positives, and divide the true positives by their total. For 1% prevalence, 80% sensitivity and 90.4% specificity that is 0.008 ÷ (0.008 + 0.09504) = 7.76%.
What is a likelihood ratio and how do I use it?
It is how much more likely a result is in people who have the condition than in people who do not. The positive one is sensitivity ÷ (1 − specificity), which is 18 for 90% and 95%. Multiply the prior odds by it: 1 to 99 becomes 18 to 99, which is 15.4%.
Can I combine two or three tests in a row?
Yes, if they are independent given the true state. Two positives from a 90% sensitive, 95% specific test at a 1% prior give 76.6% on that assumption. If the second test repeats the first one's mistakes, the true figure sits between 15.4% and 76.6%.
Does a negative result rule the condition out?
It depends on sensitivity and prevalence. At 1% prevalence, 80% sensitivity and 90.4% specificity, a negative result is right 99.78% of the time, but at 50% prevalence only 81.9%. This page gives general information, not medical advice, so interpret results with a clinician.
Related Calculators and Reference
- Probability of Two Events Calculator: joint, union and conditional chances of two events, the inputs that feed a Bayes update.
- Binomial Distribution Calculator: the chance that a given number of people in a group of n test positive.
- Confidence Interval Calculator: how uncertain a sensitivity or specificity measured on a sample really is.
- Chi Square Calculator: test whether results and condition are associated in a two by two table of counts.
- Sample Size Calculator: how many people a study needs before its error rates are pinned down.
- Stanford Encyclopedia of Philosophy: Bayes' Theorem: the theorem, its odds form and the ratio of likelihoods, with worked examples.
