Bayes' Theorem Calculator
Calculate conditional probability P(A|B) using Bayes' Theorem
About Bayes' Theorem
Bayes' Theorem describes the probability of an event based on prior knowledge of conditions related to the event.
Formula: P(A|B) = [P(B|A) × P(A)] / P(B)
Where P(B) = P(B|A) × P(A) + P(B|¬A) × P(¬A)
Example: Medical diagnosis - given a positive test result, what's the probability of having the disease?
What Is Bayes' Theorem?
Bayes' Theorem is a fundamental principle in probability theory that describes how to update the probability of an event based on new evidence. Named after Reverend Thomas Bayes, the theorem provides a mathematical framework for inverse probability — given an observed outcome B, what is the probability that a particular cause A was responsible?
The core idea is remarkably intuitive: you start with a prior probability P(A) — your initial belief about how likely A is. When you observe evidence B, you use the likelihood P(B|A) and the total probability of B to compute the posterior probability P(A|B), which is your updated belief after accounting for the evidence.
This calculator computes P(A|B) given three inputs: P(A), P(B|A), and P(B|¬A). Enter probabilities as decimals between 0 and 1 to instantly see the posterior probability and the total probability of B.
Bayes' Theorem Formula
Bayes' Theorem in its simplest form relates the conditional probability P(A|B) to the reverse conditional P(B|A). The denominator P(B) is computed using the law of total probability, summing over all possible causes.
Bayes' Theorem
Where:
- P(A)= Prior probability — your initial belief about event A before seeing evidence B
- P(B|A)= Likelihood — probability of observing evidence B given that A is true
- P(B|¬A)= Probability of observing B given that A is false (complementary likelihood)
- P(B)= Total probability = P(B|A)·P(A) + P(B|¬A)·(1−P(A))
- P(A|B)= Posterior probability — updated belief about A after observing B
Understanding the Posterior Probability
The posterior probability P(A|B) tells you how likely event A is after taking the evidence B into account. A high posterior means the evidence strongly supports A; a low posterior means the evidence points away from A.
| Scenario | P(B|A) | P(B|¬A) | What It Means |
|---|---|---|---|
| Strong evidence for A | High | Low | B is common when A occurs and rare otherwise — posterior will be larger than prior |
| Weak evidence | Similar | Similar | B is equally likely regardless of A — posterior stays close to prior |
| Deceptive evidence | Low | High | B is more common when A is false — posterior will be smaller than prior |
A crucial insight from Bayes' Theorem is the base rate fallacy: even a highly accurate test can produce a surprisingly low posterior if the prior probability is very small. For example, a test that is 99% accurate for a disease that affects 1 in 10,000 people will still produce mostly false positives.
How to Use This Calculator
Using the Bayes' Theorem calculator is straightforward:
- Enter P(A): The prior probability of event A — your initial estimate before seeing any evidence. Enter as a decimal (e.g., 0.3 for 30%). Must be between 0 and 1.
- Enter P(B|A): The probability of observing evidence B given that A is true. This is the test's sensitivity in medical contexts — how often a positive result occurs when the condition is present.
- Enter P(B|¬A): The probability of observing B when A is false. In medical testing, this is the false positive rate — how often a positive result occurs in healthy individuals.
- Read the results: The calculator outputs the posterior P(A|B) as a percentage, the total probability P(B), and P(¬A). All results update instantly as you type.
Real-World Applications
Bayes' Theorem powers critical decisions across numerous fields. In medical diagnostics, it computes the probability that a patient has a disease given a positive test result — accounting for both test accuracy and disease prevalence. Without Bayes' Theorem, doctors and patients routinely overestimate the significance of positive test results for rare conditions.
In spam filtering, Bayesian classifiers compute the probability that an email is spam given the words it contains. By continuously updating prior probabilities based on user feedback (marking emails as spam or not spam), these filters become increasingly accurate over time. In machine learning, naive Bayes classifiers are widely used for text classification, sentiment analysis, and recommendation systems.
In legal reasoning and forensic science, Bayes' Theorem helps evaluate the weight of evidence. Given a DNA match, what is the probability the suspect is the source — accounting for the rarity of the DNA profile, the size of the suspect population, and other case-specific information? Bayesian reasoning provides a rigorous framework for combining multiple pieces of uncertain evidence.
Worked Examples
Medical Diagnosis — Rare Disease
Problem:
A disease affects 1% of the population (P(A) = 0.01). A test is 95% sensitive (P(B|A) = 0.95) and has a 5% false positive rate (P(B|¬A) = 0.05). If a patient tests positive, what is the probability they actually have the disease?
Solution Steps:
- 1Step 1: Set P(A) = 0.01, P(B|A) = 0.95, P(B|¬A) = 0.05. Enter these values into the calculator.
- 2Step 2: The calculator computes P(B) = P(B|A)·P(A) + P(B|¬A)·(1−P(A)) = 0.95×0.01 + 0.05×0.99 = 0.0095 + 0.0495 = 0.059.
- 3Step 3: Bayes' Theorem gives P(A|B) = 0.95 × 0.01 / 0.059 = 0.0095 / 0.059 ≈ 0.161, or 16.1%.
Result:
Despite a 95% accurate test, a positive result means only a 16.1% chance of having the disease. This counterintuitive result occurs because the disease is so rare — most positive results are false positives from the large healthy population.
Quality Control Inspection
Problem:
In a factory, 3% of products are defective (P(A) = 0.03). An automated inspection system catches 90% of defects (P(B|A) = 0.90) but also flags 8% of good products as defective (P(B|¬A) = 0.08). What is the probability a flagged item is truly defective?
Solution Steps:
- 1Step 1: Enter P(A) = 0.03, P(B|A) = 0.90, P(B|¬A) = 0.08.
- 2Step 2: P(B) = 0.90×0.03 + 0.08×0.97 = 0.027 + 0.0776 = 0.1046.
- 3Step 3: P(A|B) = 0.90 × 0.03 / 0.1046 = 0.027 / 0.1046 ≈ 0.258, or 25.8%.
Result:
Only about 26% of flagged items are actually defective — about three-quarters of flagged items are false positives. The factory should improve the inspection system's specificity or add a secondary check.
Email Spam Classification
Problem:
About 45% of all incoming emails are spam (P(A) = 0.45). The word 'free' appears in 70% of spam emails (P(B|A) = 0.70) but only in 12% of legitimate emails (P(B|¬A) = 0.12). What is the probability an email containing 'free' is spam?
Solution Steps:
- 1Step 1: Enter P(A) = 0.45, P(B|A) = 0.70, P(B|¬A) = 0.12.
- 2Step 2: P(B) = 0.70×0.45 + 0.12×0.55 = 0.315 + 0.066 = 0.381.
- 3Step 3: P(A|B) = 0.70 × 0.45 / 0.381 = 0.315 / 0.381 ≈ 0.827, or 82.7%.
Result:
An email containing the word 'free' has an 82.7% chance of being spam — a significant increase from the 45% base rate. This illustrates how Bayesian spam filters combine multiple word probabilities to make classification decisions.
Tips & Best Practices
- ✓Always express probabilities as decimals between 0 and 1 — 30% is entered as 0.3, not 30.
- ✓If P(B|A) and P(B|¬A) are equal, the evidence B tells you nothing — the posterior equals the prior.
- ✓The larger the gap between P(B|A) and P(B|¬A), the more the evidence shifts your belief from prior to posterior.
- ✓In medical contexts, P(B|A) is test sensitivity and 1−P(B|¬A) is test specificity — keep these straight.
- ✓A low prior combined with imperfect specificity almost always means a surprisingly low posterior — this is the base rate fallacy.
Frequently Asked Questions
Sources & References
Last updated: 2026-06-06
Help us improve!
How would you rate the Bayes' Theorem Calculator?
Editorial Note
MyCalcBuddy Editorial Team
This page is maintained as an educational calculator reference.
Formula Source: Standard Mathematical References
by Various