1. Home
  2. Probability
  3. Bayes' Theorem Calculator

Bayes' Theorem Calculator

Calculate posterior probability P(A|B) using Bayes' theorem, with full step-by-step working. Switch to medical testing mode to convert sensitivity, specificity, and prevalence into PPV, NPV, and likelihood ratios.

Methodology

This calculator implements the standard Bayes' theorem formula, P(A|B) = [P(B|A) × P(A)] / P(B), and the diagnostic-test formulation of PPV and NPV used throughout clinical epidemiology and statistics. Both forms were cross-checked against multiple peer-reviewed and academic sources, including published worked examples, before publication — see the limitations section for what the calculator does and doesn't assume.

  • Formula and medical-testing math verified against independent academic sources, not just one reference
  • Results are shown with full step-by-step working, not just a final number, so you can check the calculation yourself
  • A natural-frequency breakdown (out of 10,000 people) makes the false-positive paradox concrete rather than abstract
  • Every calculation supports PDF export, one-click copy, and a shareable embed for citing this tool as a reference

How likely event A is before seeing any evidence.

Probability of the evidence occurring, given A is true.

Overall probability the evidence occurs, across all cases.

What is Bayes' theorem?

Bayes' theorem, also called Bayes' rule, is a formula for updating the probability of a hypothesis after observing new evidence. It's named after Reverend Thomas Bayes, whose work on inverse probability was published posthumously in 1763 and later extended by Pierre-Simon Laplace. Rather than treating probability as fixed, Bayes' theorem describes how a belief should change as new information arrives — this calculator automates that update.

The core formula is:

P(A|B) = [P(B|A) × P(A)] / P(B)

Where P(A) is the prior probability of event A before seeing evidence, P(B|A) is the likelihood of the evidence given A, P(B) is the overall (marginal) probability of the evidence, and P(A|B) is the posterior probability — the updated probability of A after accounting for B. When P(B) isn't known directly, it can be expanded as P(B|A)×P(A) + P(B|¬A)×P(¬A), which is exactly what this calculator's "P(B) unknown" mode does.

Key inputs: prior, likelihood, and evidence parameters

Getting a correct result depends on entering the right numbers in the right places. P(A) is your starting estimate of how likely the event is, before any evidence. P(B|A) is how likely you'd expect to see this specific evidence if the event were true. For the evidence term, you can either enter P(B) directly if you already know the overall probability of the evidence, or switch to "P(B) unknown" mode and enter P(B|¬A) — the probability of seeing the evidence even when the event is false — so the calculator can derive P(B) for you using the expanded denominator.

Medical testing mode: sensitivity, specificity, and base rate

Bayes' theorem is widely used to interpret diagnostic test results, but the terminology shifts slightly. Sensitivity (the true positive rate) is P(positive test | has the condition) — it plays the role of P(B|A). Specificity (the true negative rate) is P(negative test | no condition); its complement, 1 − specificity, is the false positive rate and plays the role of P(B|¬A). Prevalence, or base rate, is how common the condition is in the tested population, and plays the role of the prior P(A).

Worked example: suppose a disease affects 1% of a population (prevalence), and a test correctly identifies 99% of true cases (99% sensitivity) while correctly clearing 99% of healthy people (99% specificity). Even with these strong numbers, if you test positive, the probability you actually have the disease — the PPV — is only 50%. This is because, at a 1% base rate, the number of healthy people who test positive by chance (false positives) is comparable to the number of true cases. Try these numbers in medical testing mode above to see the calculation and natural-frequency breakdown.

Step-by-step calculation and formula breakdown

Every result from this calculator includes the intermediate steps: the numerator (likelihood × prior), the denominator (either the P(B) you entered, or the expanded form P(B|A)×P(A) + P(B|¬A)×P(¬A)), and the final division. Showing the full substitution lets you verify the result by hand and understand how each input affects the outcome — not just read off a number.

Interpreting the posterior probability result

The posterior probability is your updated belief after accounting for the evidence — it is not automatically "high" just because the evidence seems strong. A positive test result on a highly accurate test can still correspond to a low posterior probability if the prior (base rate) is very small — this is the false-positive paradox: even a 99%-accurate test can produce mostly false positives when the condition it's testing for is rare, because there are so many more healthy people than sick people for the small false-positive rate to act on. Always read the posterior probability alongside the prior it started from, not in isolation.

Visual aids: probability trees and natural frequencies

Percentages alone can be hard to reason about intuitively. In medical testing mode, this calculator shows a natural-frequency breakdown — "out of 10,000 people" — splitting the population into true positives, false positives, true negatives, and false negatives. Seeing the actual counts (for example, far more false positives than true positives at a low prevalence) makes the base-rate effect concrete in a way that abstract percentages often don't.

Common use cases and examples

Example 1 — Medical test screening

A disease has a 1% prevalence. A screening test has 99% sensitivity and 99% specificity. Using medical testing mode: PPV = (0.99 × 0.01) / (0.99 × 0.01 + 0.01 × 0.99) = 0.0099 / 0.0198 = 50%. Interpretation: half of all positive results are false positives, purely because the disease is rare relative to the test's small error rate.

Example 2 — Spam email filter

Suppose 5% of all emails are spam (P(A) = 0.05), and a spam filter flags 95% of actual spam as spam (P(B|A) = 0.95), but also flags 2% of legitimate emails as spam (P(B|¬A) = 0.02). Using general mode with "P(B) unknown": numerator = 0.95 × 0.05 = 0.0475; expanded denominator = 0.0475 + (0.02 × 0.95) = 0.0475 + 0.019 = 0.0665; posterior = 0.0475 / 0.0665 ≈ 71.4%. So a flagged email is genuinely spam about 71% of the time — useful context for tuning a filter's aggressiveness.

Example 3 — Urn / box problem

Two boxes: Box A has 3 red and 7 blue balls; Box B has 6 red and 4 blue balls. You pick a box at random (P(A) = 0.5) and draw a red ball. What's the probability you picked Box A? P(red|A) = 0.3, P(red|B) = 0.6, so P(¬A) = 0.5 and P(red|¬A) = 0.6. Numerator = 0.3 × 0.5 = 0.15; denominator = 0.15 + (0.6 × 0.5) = 0.15 + 0.3 = 0.45; posterior = 0.15 / 0.45 = 33.3%. Drawing red made Box A less likely, not more, since Box B has proportionally more red balls.

Multiple hypotheses and sequential updating

This calculator handles the standard two-outcome case (an event and its complement). For more than two competing hypotheses, apply Bayes' theorem to each hypothesis using the same evidence and the same expanded-denominator approach (summing the likelihood × prior across all hypotheses, not just two), then normalize so the results sum to 1. For sequential updating — chaining multiple pieces of evidence — use the posterior from one calculation as the prior for the next, assuming each new piece of evidence is independent given the true state. This is how Bayesian reasoning is extended in fields like machine learning and iterative diagnostic testing.

Common mistakes and how to avoid them

  • Confusing sensitivity with specificity. Sensitivity is about correctly catching true cases; specificity is about correctly clearing true negatives. Swapping them silently produces a wrong PPV/NPV.
  • Mixing percentages and decimals. This calculator's inputs are always percentages (enter 5 for 5%, not 0.05) — entering a raw decimal where a percentage is expected will produce a result 100x too small.
  • Mislabeling P(B|A) and P(B|¬A). These are easy to swap, especially under time pressure — double-check which one applies to "evidence given the event is true" versus "evidence given the event is false."
  • Ignoring the base rate. A strong-sounding test accuracy (95%, 99%) does not by itself tell you the posterior probability — the prior/prevalence matters just as much, sometimes more.

Relationship to related concepts (PPV, NPV, likelihood ratios)

In medical and diagnostic contexts, the posterior probability from Bayes' theorem is exactly what's called the positive predictive value (PPV) — P(condition present | positive test). Its counterpart, NPV, is P(condition absent | negative test). Likelihood ratios summarize test performance independent of prevalence: LR+ = sensitivity / (1 − specificity) tells you how much a positive result should shift your belief upward, and LR− = (1 − sensitivity) / specificity tells you how much a negative result should shift it downward. Both are shown alongside PPV and NPV in medical testing mode.

How to use this Bayes' theorem calculator

  1. Choose a mode: General for abstract probability problems, or Medical Testing for sensitivity/specificity/prevalence problems.
  2. In General mode, decide whether you know P(B) directly, or only P(B|¬A) — switch input modes accordingly.
  3. Enter each value as a percentage (e.g., 5 for 5%, not 0.05).
  4. Click Calculate to see the posterior probability (or PPV/NPV) along with the full step-by-step working.
  5. Optionally, copy the result summary or download it as a PDF for your records.

Limitations and assumptions

This calculator assumes the probabilities you enter are correctly specified — it cannot verify whether your estimated prior, sensitivity, or specificity reflect reality. It assumes the two-hypothesis case (an event and its exact complement) unless you manually chain calculations for sequential updating, and it assumes pieces of evidence are independent when used sequentially. Results are only as reliable as the inputs: garbage in, garbage out applies as much to Bayesian calculations as to any other. For decisions with real consequences (medical, financial, legal), treat this calculator as a tool for understanding the math, not a substitute for professional judgment.

Frequently asked questions

Bayes' theorem is a formula for updating the probability of an event after observing new evidence. A Bayes' theorem calculator automates this update: enter the prior probability of the event, the likelihood of the evidence given the event, and either the overall probability of the evidence or the likelihood of the evidence when the event does not occur, and the calculator returns the updated (posterior) probability.
Multiply the likelihood P(B|A) by the prior P(A), then divide by the overall probability of the evidence, P(B). If P(B) is not known directly, expand it as P(B|A) × P(A) + P(B|¬A) × P(¬A) using the complement of the prior.
You need the prior probability P(A), the likelihood P(B|A), and a way to determine P(B) — either directly, or by supplying P(B|¬A), often called the false positive rate, so the calculator can expand the denominator for you.
In medical testing mode, sensitivity plays the role of P(B|A) (probability of a positive test given disease), specificity's complement plays the role of P(B|¬A) (the false positive rate), and prevalence plays the role of the prior P(A). The calculator returns PPV, the probability of disease given a positive test.
Prior probability is your estimate of how likely an event is before seeing new evidence. Posterior probability is the updated estimate after accounting for that evidence. Bayes' theorem is the formula that converts a prior into a posterior.
The result is the probability that the event is true given the observed evidence. A P(disease|positive test) of 46% means that, among everyone who tests positive under the given prevalence and test accuracy, about 46% actually have the disease — the rest are false positives.
Yes. This calculator shows the numerator, the (expanded) denominator, and the final division as separate steps, and medical testing mode includes a natural-frequency breakdown showing how a population of 10,000 splits into true positives, false positives, true negatives, and false negatives.
Use the expanded form: P(B) = P(B|A) × P(A) + P(B|¬A) × (1 − P(A)). Substitute this into Bayes' formula in place of P(B). This calculator's "P(B) unknown" input mode does this automatically.
The false-positive paradox is the surprising result that even a highly accurate test can produce mostly false positives when the condition being tested for is rare. A Bayes' theorem calculator makes this concrete: entering a low prevalence alongside high sensitivity and specificity still yields a modest PPV, showing why base rates matter as much as test accuracy.
For more than two competing hypotheses, apply Bayes' theorem to each hypothesis separately using the same evidence, then normalize the results so they sum to 1. This calculator handles the two-hypothesis case (event vs. its complement) directly; for three or more hypotheses, repeat the calculation for each one.
Use the posterior probability from the first test as the prior probability for the second test, then apply Bayes' theorem again with the second test's likelihood. Repeat for each additional piece of evidence, assuming the tests are independent given the true state.
The most common mistakes are swapping sensitivity and specificity, entering a percentage where a decimal is expected (or vice versa), confusing P(B|A) with P(A|B), and forgetting to account for the base rate (prevalence) when interpreting a positive test result.

Related calculators