What the Bayes theorem calculator computes
Bayes' theorem answers a specific question: given that I observed evidence , how likely is each scenario now?
The calculator works with one observation at a time and uses three kinds of probability:
- Prior: the probability of a scenario before you condition on , such as .
- Likelihood: the probability of observing within a particular scenario, such as .
- Posterior: the probability of the scenario among the outcomes where occurred, such as .
The headline result is Updated probability of A, which is the posterior . In Advanced mode, the calculator also shows the updated probabilities of B and C.
The Bayes formula and what each probability means
For two scenarios, A and its complement (shown in the calculator as Not A), the Bayes formula is:
Read it from the top down. The numerator is the joint probability : the share of all outcomes that are both in A and show the evidence. The denominator is , the share of all outcomes that show the evidence, regardless of scenario. Dividing one by the other restricts attention to the outcomes where happened and asks what fraction of those belong to A.
It is easy to swap the two conditional probabilities in Bayes’ formula. asks how often the evidence appears when A is true. asks how often A is true when the evidence has appeared. The posterior depends on the prior and the evidence rates across all scenarios.
For the calculator, let be the prior of scenario and its likelihood, both as fractions. The calculation has three stages:
- Joint probability for each scenario: .
- Total evidence probability: .
- Posterior for each scenario, if : .
Multiply a fraction by 100 to show it as a percentage.
How to use the calculator
Enter percentages as values from 0 to 100 inclusive, with up to four decimal places. Type 1 for 1%, not 0.01. The typed fields accept steps of 0.0001 percentage points, while the sliders move in whole percentage points.
Simple mode (A and Not A)
Simple is the default. It splits all outcomes into A and Not A, so you provide three numbers:
- Prior for A, P(A): defaults to 1%.
- Evidence given A, P(E | A): defaults to 90%.
- Evidence without A, P(E | not A): defaults to 5%.
The prior for Not A is derived automatically as .
Advanced mode (A, B, and C)
Advanced splits all outcomes into three scenarios. This is the mode to use when you want a Bayes theorem calculator for 3 events. The scenarios must be mutually exclusive (no outcome belongs to two scenarios) and exhaustive (every outcome belongs to one of them). The fields are:
- Prior for A, P(A): defaults to 1%.
- Prior for B, P(B): defaults to 49%.
- Evidence given A, P(E | A): defaults to 90%.
- Evidence given B, P(E | B): defaults to 5%.
- Evidence given C, P(E | C): defaults to 10%.
The prior for C is not typed. The calculator shows it as Remaining prior for C, equal to .
The field labeled Evidence without A, P(E | not A) in Simple becomes Evidence given B, P(E | B) in Advanced. In Simple, it is the evidence rate across everything outside A. In Advanced, it applies only to B, and C has its own separate rate. Switching modes keeps the entered number, so check that it represents the evidence rate within the right group.
What this calculator does not do
The tool evaluates a single observation at a time. It has no mode for sequential evidence (updating again after a second observation), for overlapping scenarios, or for Naive Bayes classification. If your scenarios overlap, redefine them as non-overlapping categories before entering them.
Bayes formula examples with actual values
Example 1: a defective-part scanner (two scenarios)
A factory scanner flags parts as possibly defective. Suppose 1% of parts are defective. The scanner flags 90% of defective parts and also flags 5% of good parts by mistake. If a part is flagged, how likely is it to be defective?
This is the Defective-part scanner preset, and it is what the calculator loads by default (and what Reset restores). With , , and :
Even though the scanner catches 90% of defective parts, a flagged part has only about a 15.4% chance of being defective. The reason is that good parts vastly outnumber defective ones, so a 5% false-flag rate on 99% of parts produces more flags than the 90% hit rate on 1% of parts.
A natural-frequency view makes the same point. Out of 10,000 parts, 100 are defective and about 90 of those are flagged. Of the 9,900 good parts, about 495 are flagged. That gives 585 flagged parts, and of them are defective.
Example 2: three production lines (three scenarios)
Now suppose parts come from three lines, and you want the updated probability for each line after a flagged part appears. Using the Three production lines preset: line A makes 1% of parts, line B makes 49%, and line C makes the remaining 50%. The flag rates are 90% for A, 5% for B, and 10% for C.
| Scenario | Prior | Evidence rate | Joint with E |
|---|---|---|---|
| A | 1% | 90% | 0.9% |
| B | 49% | 5% | 2.45% |
| C | 50% | 10% | 5% |
The total evidence is . Each posterior divides one joint value by that same total:
| Scenario | Calculation | Updated probability |
|---|---|---|
| A | 10.7784% | |
| B | 29.3413% | |
| C | 59.8802% |
Line A has the highest flag rate, yet C is the most probable source of a flagged part because it contributes the most parts and flags a meaningful share of them. The exact posteriors sum to 100%. The three displayed values above add to 99.9999% because each is rounded individually, which is a display effect, not an error in the calculation.
Example 3: a stronger prior
Change the scanner example so that 10% of parts are defective, keeping the 90% and 5% rates. The joint values are and , so and . Raising the prior from 1% to 10% lifts the updated probability from about 15.4% to about 66.7%. At a prior of 0.1%, the same scanner yields only about 1.76991%. The evidence stays equally strong in each case. Only the starting point moves.
Reading the calculation steps
The Calculation steps section appears under the result when the inputs are valid. It shows three stages.
- Multiply each prior by its evidence rate, using your entered values.
- Add the contributions to get .
- Divide each displayed scenario's contribution by that total to get its posterior.
Use this to check your own work or to see which scenario drives the denominator. If any input field is invalid, the steps are hidden until you fix it.
If you prefer to work with raw percentage numbers by hand, divide each prior-times-likelihood product by 100 to get the joint percentage, sum the joint percentages to get the evidence percentage, then divide a joint percentage by the evidence percentage and multiply by 100.
Reading the probability tree
The Bayes theorem tree diagram starts with a single node, All outcomes, which branches into your scenarios. Each branch carries that scenario's prior. A second column, labeled Joint with E, shows the probability of being in that scenario and observing the evidence. Thicker branches represent larger probabilities.
Be careful about what the second column means. Its values are joint probabilities measured against all outcomes. They are not the likelihoods you entered, and they are not the posteriors. In the scanner example, the second column reads 0.9% and 4.95%. Adding those gives , and dividing either one by the sum gives the posterior.
If the inputs are invalid, the tree prompts you to enter valid probabilities. The highlighted field shows the specific error.
Using the same calculation in Excel
You can reproduce the two-scenario calculation in Excel. Enter probabilities with the percent sign, such as 1%, or enter equivalent decimal fractions such as 0.01 in cells formatted as numbers.
| Cell | Label | Value or formula |
|---|---|---|
| B1 | Prior P(A) | 1% |
| B2 | P(E given A) | 90% |
| B3 | P(E given not A) | 5% |
| B4 | Joint with A | =B1*B2 |
| B5 | Joint with Not A | =(1-B1)*B3 |
| B6 | P(E) | =B4+B5 |
| B7 | P(A given E) | =IF(B6>0,B4/B6,"undefined") |
With the scanner values, B7 returns approximately 0.153846, or 15.3846% when formatted as a percentage with four decimal places.
For three scenarios, put the priors for A and B in two cells, compute the prior for C as =1-priorA-priorB, multiply each prior by its own evidence rate, add the three products for , and divide each product by that total. Also check that the A and B priors do not sum to more than 100%, since that makes the prior for C negative, which is invalid.
Small differences in the last digits are possible. The calculator computes products and sums on an integer grid of 0.0001 percentage points, then uses full-precision ratios before formatting, while Excel works in floating-point arithmetic throughout.
Edge cases and messages
Zero prior. In Advanced mode, A and B may sum to exactly 100%, which gives C a prior of zero. A scenario with zero prior contributes zero even if its entered evidence rate is positive, and its posterior is zero as long as . A sum above 100% is invalid.
Zero evidence probability. If , the posterior is undefined, because you would be conditioning on something that cannot happen under your inputs. This occurs when every scenario with a positive prior has a zero likelihood of producing . The calculator flags the problem and shows an em dash (—) instead of a posterior.
Evidence that changes nothing. If at least two scenarios have positive priors and all positive-prior scenarios share the same nonzero likelihood, the calculator shows the advisory This evidence leaves the priors unchanged. The common positive likelihood makes , so for each positive-prior scenario. For example, a prior of 20% with a 40% evidence rate in both A and Not A gives joint values of 8% and 32%, a total of 40%, and a posterior of 20%, identical to the prior.
Display formatting. Displayed probabilities use up to six significant digits. A positive percentage below 0.000001% appears in scientific notation. If a posterior is below 100% but would round to 100% on screen, the tool shows >99.9999% so that near-certainty is not mistaken for certainty. An exact 100% is shown as 100%.
Tips for getting reliable results
- Choose the right reference class for the prior. The prior should describe the population your observation comes from. A defect rate across a whole factory is the wrong prior for a batch from a line you already know is troubled.
- Keep the evidence definition consistent. The likelihoods must all refer to the same observation . A 90% hit rate for "flagged" cannot be paired with a 5% rate for "flagged twice."
- Make scenarios exhaustive. If you list only some possibilities, the derived remainder may not match reality. In Simple mode, Not A automatically covers everything else. In Advanced, check the
Remaining prior for C. - Test sensitivity. Slide the prior up and down. If the conclusion flips across a plausible range, your answer depends heavily on the prior, and that is worth knowing.
- Remember that inputs are estimates. The calculator computes a posterior from the values you enter. Uncertainty in those values affects how you interpret the result.
Copy, Export, Reset, and Help
- Copy places a summary of the calculation on your clipboard. It is disabled while the calculation is invalid.
- Export opens your browser's print dialog, so you can print the result or save it as a PDF.
- Reset restores the Simple mode scanner preset.
- Help explains the inputs, both modes, the steps, the tree, and the zero-evidence condition.
Frequently asked questions
What is Bayes' theorem in simple terms?
It is a rule for revising a probability when you learn something new. You start with a prior, weigh it by how well each scenario explains the evidence, and rescale so the updated probabilities across all scenarios add to 100%.
What is the difference between and ?
is how often the evidence shows up when A is true. is how often A is true when the evidence has shown up. The scanner example shows how far apart they can be, with a likelihood of 90% and a posterior of about 15.4%.
Can I use this for more than three scenarios?
Not directly. The calculator supports two or three scenarios. You can sometimes merge categories to fit, as long as the merged groups remain mutually exclusive and exhaustive.
Can I update repeatedly with several pieces of evidence?
The calculator evaluates one observation at a time and has no sequential mode. To update again, you can use the first posterior as the next prior and supply the likelihood of the new observation given both the scenario and the earlier evidence. If the observations are conditionally independent within each scenario, the new likelihood depends only on the scenario.
Why does a very accurate test still give a low updated probability?
Because the prior matters. When the scenario is rare, even a small false-positive rate applied to the large majority produces many false alarms compared with the true positives from the rare group.
Why do the displayed posteriors sometimes add to 99.9999% or 100.0001%?
Each posterior is rounded separately for display. The exact values sum to 100%.
Is the result a prediction?
It is a conditional probability computed from your inputs. It is only as good as the priors and likelihoods you supply.
Read the formula definitions, supported input ranges, and limitations before using this estimate.