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
- 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.
- 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.
- 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.
- 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?
Why is the answer so low for a test that detects 95% of cases?
What is the difference between P(A|B) and P(B|A)?
What is a prior probability?
Do I need P(B) as an input?
Can I apply Bayes theorem repeatedly?
Related Statistics Calculators
Probability Calculator
Calculate probability of events, complements, unions, and intersections. Free online probability calculator for statistics.
Standard Deviation Calculator
Calculate standard deviation, variance, mean, and more for any dataset. Supports population and sample statistics. Free online tool.
Z-Score Calculator
Calculate z-scores, find values from z-scores, and determine probabilities. Free online z-score calculator with bell curve visualisation.
Binomial Calculator
Calculate binomial probabilities, cumulative distributions, and expected values. Free online binomial distribution calculator with bar chart.
Normal Distribution Calculator
Calculate probabilities for normal distributions. Find areas under the bell curve, percentiles, and inverse values. Free online tool.
Correlation Calculator
Calculate Pearson correlation coefficient, R-squared, and regression line. Free online correlation calculator with scatter plot.