induwara.lk
induwara.lkStatistics · Probability

Bayes' Theorem Calculator

Enter a prior P(A), a true-positive rate P(B|A) and a false-positive rate P(B|¬A) to get the posterior probability P(A|B), the evidence P(B), a step-by-step substitution and a probability tree. It is the fastest way to settle the classic false-positive paradox, runs entirely in your browser, and needs no signup.

By Induwara AshinsanaUpdated Jun 11, 2026
Bayes' theorem calculator
Input format

Base rate of A before any evidence.

True-positive rate / sensitivity: chance of B when A is true.

Chance of B when A is false. Equals 1 − specificity.

Presets
Posterior P(A|B)
16.67%
Exact: 0.1667
Complement P(¬A|B)
83.33%
Exact: 0.8333
Evidence P(B)
5.94%
Exact: 0.0594 (the normaliser)

Observing B raises the probability of A from 1.0% (prior) to 16.7% (posterior). Even with a 99.0% true-positive rate, the posterior can stay modest when A is rare — false positives outnumber true positives.

Step-by-step substitution

P(¬A) = 1 − 0.0100 = 0.9900

P(B) = 0.9900·0.0100 + 0.0500·0.9900 = 0.0594

P(A|B) = (0.9900·0.0100) / 0.0594 = 0.0099 / 0.0594 = 0.1667

P(¬A|B) = 1 − 0.1667 = 0.8333

Probability tree

BranchOutcomeJointProbability
A → BTrue positive0.9900·0.01000.0099
A → ¬BFalse negative(1−0.9900)·0.01000.0001
¬A → BFalse positive0.0500·0.99000.0495
¬A → ¬BTrue negative(1−0.0500)·0.99000.9405
Total (must equal 1)1.0000

Cross-check. The odds form gives prior odds 0.0101 × likelihood ratio 19.8000 = posterior odds 0.2000, i.e. P(A|B) = 0.1667. It matches the direct calculation, as it must — the result is verified.

Method: P(A|B) = P(B|A)·P(A) / [P(B|A)·P(A) + P(B|¬A)·P(¬A)] (Bayes' theorem with the law of total probability). Sources cited below the calculator. No data leaves this page.

How it works

Bayes' theoremupdates a prior belief about a hypothesis A once you observe evidence B. It rests on two simpler rules of probability and combines them into a single formula. Throughout, let A be the event of interest (“has the condition”, “is spam”) and B the observed evidence (“tests positive”, “contains the word”).

The full statement, with the denominator expanded, is:

P(A|B) = P(B|A)·P(A) / [ P(B|A)·P(A) + P(B|¬A)·P(¬A) ]

  1. Complement the prior.P(¬A) = 1 − P(A). This is the basic complement axiom of probability (Grinstead & Snell).
  2. Find the evidence by total probability. The chance of seeing B at all splits across the two ways it can happen — when A is true and when A is false:

    P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A)

    This marginal P(B) is the normalising constant. Source: NIST/SEMATECH e-Handbook; Grinstead & Snell §4.
  3. Apply Bayes' theorem. Divide the true-positive term by the evidence to get the posterior P(A|B) = P(B|A)·P(A) / P(B). This is the same rule scikit-learn states for Naive Bayes, P(y|x) = P(y)·P(x|y) / P(x).
  4. Complement the posterior. P(¬A|B) = 1 − P(A|B), the probability that A is false despite the evidence.

The calculator above also recomputes the posterior a second, independent way — the odds form. The prior odds P(A)/P(¬A) are multiplied by the likelihood ratio P(B|A)/P(B|¬A) to give the posterior odds, which convert back to a probability via odds / (1 + odds). Because this uses a ratio of ratios rather than the normalisation above, agreement between the two routes is a genuine correctness check, and the four joint probabilities of the tree are confirmed to sum to 1. When a likelihood is 0 the evidence can vanish (P(B) = 0); the tool then reports the posterior as undefined rather than dividing by zero.

A key intuition the tool makes visible: the posterior depends heavily on the base rate. A highly sensitive test applied to a rare condition still produces mostly false positives, because the large healthy population contributes many false alarms while the small affected population contributes few true ones. That is the false-positive paradox, and the probability tree shows exactly where the numbers come from.

Worked examples

Rare-disease screening — posterior 16.67% (the Demo preset)

  1. Prior P(A) = 0.01, sensitivity P(B|A) = 0.99, false-positive P(B|¬A) = 0.05
  2. P(¬A) = 1 − 0.01 = 0.99
  3. P(B) = 0.99·0.01 + 0.05·0.99 = 0.0099 + 0.0495 = 0.0594
  4. P(A|B) = 0.0099 / 0.0594 = 0.1667 (16.67%)
  5. P(¬A|B) = 1 − 0.1667 = 0.8333 (83.33%)
  6. Read-out: a positive result still means only ~17% chance of the disease

Naive-Bayes spam filter — posterior 84.21%

  1. Prior P(spam) = 0.40, P(word|spam) = 0.80, P(word|ham) = 0.10
  2. P(¬spam) = 1 − 0.40 = 0.60
  3. P(word) = 0.80·0.40 + 0.10·0.60 = 0.32 + 0.06 = 0.38
  4. P(spam|word) = 0.32 / 0.38 = 0.8421 (84.21%)
  5. Seeing this word pushes the spam probability from 40% up to ~84%

The boundaries — impossible and certain priors

  1. Impossible prior: P(A) = 0, P(B|A) = 0.90, P(B|¬A) = 0.10
  2. P(B) = 0.90·0 + 0.10·1 = 0.10 → P(A|B) = 0 / 0.10 = 0.0000 (if A can't occur, B never implies it)
  3. Certain prior: P(A) = 1, P(B|A) = 0.50, P(B|¬A) = 0.20
  4. P(B) = 0.50·1 + 0.20·0 = 0.50 → P(A|B) = 0.50 / 0.50 = 1.0000
  5. Undefined edge: both likelihoods 0 make P(B) = 0, so the posterior is shown as 'undefined' rather than dividing by zero

Frequently asked questions

Sources & references

The formulas on this page were last cross-checked against these sources on 2026-06-11. Bayes' theorem is a stable mathematical identity, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.