Bayes' Theorem Calculator
Calculate the posterior probability P(A|B) from a prior P(A) and two likelihoods using Bayes' theorem, with a probability-tree diagram and step-by-step solution.
Enter each probability as a decimal between 0 and 1 (e.g. 0.95 for 95%). A classic example is a medical test: P(A) = chance of having the disease, P(B|A) = test sensitivity, P(B|¬A) = false positive rate.
Probability Tree Diagram
The two highlighted "B" branches are the only ones that matter once B is observed — P(A|B) is the top one's share of both combined.
P(A|B) = P(A∩B) / P(B) = 0.0095 / 0.059 = 0.161
Step-by-Step Solution
Here's exactly how this answer was calculated, one step at a time.
- 1
Write down the given probabilities
P(A) = 0.01, P(B|A) = 0.95, P(B|¬A) = 0.05
P(A) is the prior probability of A, and P(B|A), P(B|¬A) are the likelihoods of observing B under each scenario.
- 2
Find P(¬A), the complement of A
P(¬A) = 1 − P(A) = 1 − 0.01 = 0.99
This is the probability that A does not occur.
- 3
Find the joint probability P(A ∩ B)
P(A ∩ B) = P(A) × P(B|A) = 0.01 × 0.95 = 0.0095
This is the probability that both A occurs and B is observed, following the top branch of the probability tree.
- 4
Find the joint probability P(¬A ∩ B)
P(¬A ∩ B) = P(¬A) × P(B|¬A) = 0.99 × 0.05 = 0.0495
This is the probability that A does not occur but B is still observed, following the bottom branch of the probability tree.
- 5
Find the total probability of B (law of total probability)
P(B) = P(A ∩ B) + P(¬A ∩ B) = 0.0095 + 0.0495 = 0.059
B can happen in two ways — via A or via ¬A — so adding both joint probabilities gives the total chance of observing B.
- 6
Apply Bayes' theorem to find P(A|B)
P(A|B) = P(A ∩ B) / P(B) = 0.0095 / 0.059 = 0.161
This means that once B is observed, there is a 16.1% chance that A is actually true — this is the updated ('posterior') probability.
✓ Final Answer: P(A|B) = 0.161 (16.1%)
Free Online Bayes' Theorem Calculator
This Bayes' theorem calculator finds the posterior probability P(A|B) — the updated probability of event A after observing evidence B — from a prior probability and two likelihoods. Enter P(A), P(B|A), and P(B|¬A), and the calculator instantly returns P(A|B), the total probability of B, and both joint probabilities, complete with a probability-tree diagram and a full step-by-step solution.
Whether you're a student solving Bayesian probability problems, a data scientist building a Naive Bayes classifier, or someone interpreting a medical test result, this Bayes' theorem solver handles the entire calculation for you and shows exactly how the answer was derived using the law of total probability.
Bayes' Theorem Formula
Bayes' theorem describes how to update the probability of an event based on new evidence. The formula is:
P(A|B) = [P(B|A) × P(A)] / P(B)
Here, P(A) is the prior probability — what you believed about A before seeing any evidence. P(B|A) is the likelihood — how probable the evidence B is if A is actually true. P(A|B) is the posterior probability — your updated belief about A after observing B. When P(B) isn't given directly, it's calculated using the law of total probability: P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A).
How to Use This Bayes' Theorem Calculator
Using the calculator takes just three steps. First, enter P(A), the prior probability of the event you're interested in. Second, enter P(B|A), the probability of observing the evidence if A is true. Third, enter P(B|¬A), the probability of observing the same evidence if A is false. The calculator instantly computes P(A|B) — the probability that A is true given that you've observed B — along with a probability-tree diagram showing exactly how the numbers combine.
In the diagram, the tree splits first on whether A happens or not, then on whether B is observed within each branch. Once B is actually observed, only the two cyan-highlighted 'B' branches remain relevant — P(A|B) is simply the top branch's joint probability divided by the sum of both.
Worked Example: The Classic Medical Test Problem
Suppose a disease affects 1% of a population (P(A) = 0.01). A test for the disease is 95% accurate at detecting it when present (P(B|A) = 0.95, the sensitivity), but also gives a false positive 5% of the time on healthy people (P(B|¬A) = 0.05). If someone tests positive, what's the actual probability they have the disease?
P(A ∩ B) = 0.01 × 0.95 = 0.0095. P(¬A ∩ B) = 0.99 × 0.05 = 0.0495. P(B) = 0.0095 + 0.0495 = 0.059. So P(A|B) = 0.0095 / 0.059 ≈ 0.161, or about 16.1% — a surprisingly low number given a '95% accurate' test. This counterintuitive result is exactly why Bayes' theorem is essential: it correctly accounts for how rare the disease is in the first place (the base rate), something an accuracy percentage alone doesn't capture.
Why Base Rates Matter (The Base Rate Fallacy)
The medical test example above illustrates the base rate fallacy — the common mistake of ignoring how rare or common an event is beforehand and focusing only on a test's accuracy. Even a highly accurate test can produce mostly false positives if the condition being tested for is rare, simply because there are so many more healthy people who could trigger a false alarm than sick people who could trigger a true one. Bayes' theorem is the correct mathematical tool for combining accuracy with base rate to get a truthful answer.
Where Bayes' Theorem Is Used
Bayes' theorem is one of the most important tools in probability and statistics, with applications across many fields:
- Students and teachers use it throughout probability, statistics, and machine learning coursework.
- Medical diagnostics rely on it to correctly interpret test results by combining test accuracy with disease prevalence.
- Spam filters and Naive Bayes classifiers use it to calculate the probability an email is spam given the words it contains.
- Legal and forensic reasoning uses Bayesian analysis to weigh evidence like DNA matches against how rare a given genetic profile is.
- Search and recommendation engines use Bayesian updating to refine predictions as new user behavior data comes in.
Frequently Asked Questions
What is Bayes' theorem?
Bayes' theorem is a formula for updating the probability of an event based on new evidence: P(A|B) = [P(B|A) × P(A)] / P(B), where P(A) is the prior probability and P(A|B) is the updated (posterior) probability after observing B.
What's the difference between prior and posterior probability?
The prior probability, P(A), is your belief about an event before seeing any evidence. The posterior probability, P(A|B), is your updated belief after observing evidence B. Bayes' theorem is the formula that connects the two.
How do I find P(B) if it isn't given directly?
Use the law of total probability: P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A). This calculator computes P(B) automatically from your prior and two likelihoods, so you don't need to know it in advance.
Why does Bayes' theorem give a low result for accurate medical tests?
This happens due to the base rate fallacy: when a disease is rare, even a highly accurate test generates more false positives (from the large healthy population) than true positives (from the small sick population), pulling the posterior probability down.
What is the difference between Bayes' theorem and conditional probability?
Conditional probability, P(A|B) = P(A ∩ B) / P(B), is the basic definition. Bayes' theorem rearranges this using P(B|A) instead of P(A ∩ B) directly, which is useful when you know the likelihood of evidence under a hypothesis but not the raw joint probability.