Bayes' Theorem & Conditional Probability Calculator

Bayes' theorem updates a belief after new evidence: P(A|B) = P(B|A) × P(A) / P(B). Use it for medical tests, spam filters (naive Bayes), machine learning and any "given that" question.

Each tab starts with a short guide for beginners, then a live calculator with step-by-step working. Your numbers never leave this browser.

The big idea: you already believe something (the prior). Then you see new evidence. Bayes tells you how far to move your belief, and the answer is often not what your gut says.

Picture 10,000 people instead of formulas. Split them into sick and healthy. Tests find most sick people, but they also wrongly flag a few healthy ones. When you get a positive, you are standing in the crowd of everyone who tested positive. The question is: how many of them are truly sick?

The trap: if the thing is rare, the healthy crowd is huge, so even a small false-alarm rate creates many false positives. That is why a "90% accurate" test can mean only a ~10% chance you are sick.

  • Prior = your belief before the evidence.
  • Likelihood = how likely the evidence is if your belief is true.
  • Posterior = your updated belief after the evidence. This is the answer.

Try it: press Rare disease below, then change the prevalence from 1% to 20% and watch the posterior jump.

Your probabilities — type values in %, results update live

9.17%
Posterior P(A | B): belief in A after seeing B
0.11%
P(A | not B): belief in A if B is NOT seen
9.81%
P(B): overall chance of seeing the evidence

Out of 10,000 people

This is the same math as Bayes, just counted as people. Read it left to right.

90
A is true and we see evidence B (true positives)
891
A is true is false but we see evidence B (false positives)
10
A is true but no we see evidence B (missed)
9009
Neither (true negatives)

Everyone who we see evidence B: teal is genuinely A, pink is a false alarm.

9.2% real90.8% false alarms

Step-by-step working

Step 1: Write down what you know

Prior P(A) = 1%, P(B | A) = 90%, P(B | not A) = 9%.

Step 2: How likely is the evidence overall? (total probability)

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

= 0.9 × 0.01 + 0.09 × 0.99 = 0.0981

Two ways to see B: A is true and B shows up, or A is false and B shows up anyway. We add both.

Step 3: Apply Bayes' theorem

P(A | B) = P(B|A)·P(A) / P(B)

= 0.009 / 0.0981 = 9.17%

Step 4: Check it with people

981 people we see evidence B. Only 90 of them really are A. 90 / 981 = 9.17%. Same answer, easier to picture.

Step 5: What it means

The evidence raised your belief from 1% to 9.17%, but that is much lower than 90%. P(B|A) and P(A|B) are different things. The low prior (base rate) is holding the answer down.

How this calculator works

The Bayes and Medical Test tabs use P(A|B) = P(B|A)·P(A) / [P(B|A)·P(A) + P(B|¬A)·P(¬A)]. The spam tab applies naive Bayes with Laplace smoothing and sums log-probabilities to avoid underflow. The table tab divides a cell by the grand total for joint probability, or by a row or column total for conditional probability. The ML tab shows Beta-Binomial updating, where the posterior is the prior plus the observed counts.

Results update live as you type. Values are for learning and are not medical or legal advice.

Common questions