Skip to content

Bayes Theorem Calculator — Step-by-Step Solutions

The Bayes Theorem Calculator helps you compute conditional probabilities step by step. Enter your prior probability, likelihood, and evidence to find the posterior probability P(A|B).

The calculator offers four modes: basic P(A|B) calculation, computation with the complement using the law of total probability, an SVG tree diagram visualisation, and real-world examples including medical testing, spam filtering, weather forecasting, and manufacturing quality control.

Your calculations will appear here

How to Use the Bayes Theorem Calculator

  1. Basic P(A|B): enter the prior P(A), the evidence probability P(B) and the likelihood P(B|A). All values are probabilities between 0 and 1, so enter 5% as 0.05.
  2. With Complement: use this when you do not know P(B) directly. Enter the prior P(A), the likelihood P(B|A) and the false positive rate P(B|not A). The calculator works out P(B) for you with the law of total probability.
  3. Tree Diagram draws the same problem as a probability tree, and Real-World Examples loads ready-made scenarios, such as a medical test, so you can see how the inputs map to a story.
  4. The result is the posterior probability P(A|B), shown as a decimal and a percentage, with the working below.

Formula and Theory

Bayes theorem tells you how to update a probability when new evidence arrives. You start with a prior P(A), the chance of the event before seeing any evidence. Given evidence B, the updated or posterior probability is P(A|B) = P(B|A) x P(A) / P(B).

The denominator P(B) is the total probability of seeing the evidence. When the event A either happens or does not, P(B) = P(B|A) P(A) + P(B|not A) P(not A). That is why the false positive rate P(B|not A) matters so much: it measures how often the evidence appears even when A is false.

The key lesson is the effect of the base rate. If A is rare, even strong evidence leaves a modest posterior, because false alarms from the large not-A group can outnumber true detections from the small A group. Confusing P(B|A) with P(A|B) is called the prosecutor's fallacy.

Worked Examples

Example 1: Medical screening test

Problem: A condition affects 1% of people. A test detects it 95% of the time when present and gives a false positive 10% of the time when absent. If you test positive, what is the chance you have it?

Solution: P(A) = 0.01, P(B|A) = 0.95, P(B|not A) = 0.10. P(B) = 0.95 x 0.01 + 0.10 x 0.99 = 0.0095 + 0.099 = 0.1085. P(A|B) = 0.0095 / 0.1085 = 0.0876.

Answer: About 8.76%

Example 2: Spam filter

Problem: 40% of email is spam. The word "prize" appears in 60% of spam and 5% of normal mail. What is the chance a message containing "prize" is spam?

Solution: P(spam) = 0.4, P(word|spam) = 0.6, P(word|not spam) = 0.05. P(word) = 0.6 x 0.4 + 0.05 x 0.6 = 0.24 + 0.03 = 0.27. P(spam|word) = 0.24 / 0.27 = 0.8889.

Answer: About 88.89%

Example 3: Which machine made the faulty part?

Problem: Machine A makes 30% of parts and 2% of its parts are faulty. The other machines make 70% with 1% faulty. A faulty part is found. What is the probability it came from machine A?

Solution: P(A) = 0.3, P(faulty|A) = 0.02, P(faulty|not A) = 0.01. P(faulty) = 0.02 x 0.3 + 0.01 x 0.7 = 0.006 + 0.007 = 0.013. P(A|faulty) = 0.006 / 0.013 = 0.4615.

Answer: About 46.15%

Example 4: When P(B) is already known

Problem: Use the basic mode with P(A) = 0.01, P(B) = 0.1085 and P(B|A) = 0.95.

Solution: P(A|B) = 0.95 x 0.01 / 0.1085 = 0.0095 / 0.1085 = 0.0876, the same answer as the screening example, since P(B) = 0.1085 was computed there.

Answer: 0.0876 (8.76%)

Frequently Asked Questions

What is Bayes theorem in simple terms?
It is a rule for revising a probability after you see new evidence. You combine how likely the evidence is if your idea is true with how likely your idea was to begin with.
Why is the answer so low for a test that detects 95% of cases?
Because the condition is rare. Out of 10,000 people, 100 have it and 95 test positive, while 990 of the 9,900 healthy people also test positive. So only 95 of 1,085 positives are real, about 8.8%.
What is the difference between P(A|B) and P(B|A)?
P(B|A) is the chance of the evidence if A is true; P(A|B) is the chance A is true given the evidence. They are usually different, and Bayes theorem converts one into the other.
What is a prior probability?
It is your starting probability for the event before using the new evidence, often a base rate from population data, such as the share of people who have a condition.
Do I need P(B) as an input?
Only in the basic mode. If you know the false positive rate instead, use the With Complement mode, which computes P(B) as P(B|A) P(A) + P(B|not A) P(not A).
Can I apply Bayes theorem repeatedly?
Yes. The posterior from one piece of evidence becomes the prior for the next, as long as the pieces of evidence are independent given the event.

Related Statistics Calculators

Related Articles