# Bayes' Theorem & Conditional Probability Calculator

Calculate posterior probability, PPV, and NPV from prevalence, sensitivity, and false positive rate, with a probability tree and confusion matrix.

---

- **Canonical URL:** https://dothecalculation.com/calculators/bayes-theorem-calculator
- **Category:** Math calculators
- **Publisher:** Do The Calculation (https://dothecalculation.com)
- **Cost:** Free, no account or sign-up required
- **Privacy:** Runs entirely in the browser; inputs are never sent to a server
- **Methodology:** https://dothecalculation.com/methodology

---

## Bayes Theorem & Conditional Probability Calculator

Enter a base rate, a test's sensitivity, and its false positive rate to get the posterior probability, PPV, and NPV — with a population breakdown showing why base rate matters.

- Posterior, PPV, and NPV from Bayes' Theorem
- Probability tree and confusion-matrix visuals
- 10,000-person population breakdown

## Bayes' Theorem: Updating a Probability with New Evidence

Bayes' Theorem describes how to update a prior probability belief once you observe new evidence:

$$P(A \mid B) = \frac{P(B \mid A) \cdot P(A)}{P(B)}$$

\(P(A \mid B)\) is the posterior — the updated probability of \(A\) once you know \(B\) happened. \(P(B \mid A)\) is the likelihood: how probable the evidence is if \(A\) is true. \(P(A)\) is the prior — what you believed before seeing any evidence. \(P(B)\) is the marginal probability of the evidence across every possibility, expanded with the Law of Total Probability:

$$P(B) = P(B \mid A) \cdot P(A) + P(B \mid A^c) \cdot (1 - P(A))$$

The single most important intuition here: the prior matters as much as the test itself. A highly accurate test applied to a rare condition still produces mostly false alarms, because there are so many more people without the condition than with it. That's exactly what this calculator is built to show.

## How to Use This Calculator

Enter the prior probability (base rate/prevalence), the sensitivity (true positive rate), and the false positive rate as percentages. The calculator applies Bayes' Theorem to compute the posterior probability, the positive predictive value (PPV), and the negative predictive value (NPV), and breaks a population of 10,000 down into true/false positives and negatives so the effect of a low base rate is visible directly.

## Worked Example: 1% Prevalence, 99% Sensitivity, 5% False Positive Rate

$$P(B) = P(B|A)P(A) + P(B|A')(1-P(A)) = (0.99)(0.01) + (0.05)(0.99) = 0.0594$$

$$P(A|B) = \frac{(0.99)(0.01)}{0.0594} \approx 0.1667 \; (16.67\%)$$

In a population of 10,000: 100 people actually have the condition (of whom 99 test positive and 1 tests negative), and 9,900 do not have it (of whom 495 still test positive and 9,405 correctly test negative). Even with a 99% sensitive test, only about 1 in 6 positive results (99 out of 594 total positives) is a true positive — because the 5% false-positive rate applied to the much larger healthy population produces more false alarms than true detections.

## Medical Diagnostic Testing and the Base Rate Fallacy

This calculator's three inputs map directly onto how diagnostic tests are evaluated. Sensitivity is the true positive rate, \(P(\text{Test}^+ \mid \text{Disease}^+)\). Specificity is the true negative rate, \(P(\text{Test}^- \mid \text{Disease}^-)\); the false positive rate you enter is \(1 - \text{Specificity}\).

The **Base Rate Fallacy** is the intuition failure this tool is designed to correct: people tend to focus on a test's accuracy and ignore how rare the condition is. Screening for a disease with 0.1% prevalence using a 99%-sensitive, 99%-specific test still means most positive results are false — because in a population of 1,000, roughly 1 truly sick person tests positive alongside about 10 false positives from the other 999 healthy people. Sensitivity and specificity describe the test; PPV describes what a positive result *actually means for the patient*, and the two are only close together when the base rate is high.

This is why single-test screening for rare conditions is typically followed by a confirmatory second test: using the first test's posterior probability as the second test's prior sharply reduces the false-positive share, since the "population" being tested the second time is no longer the general public but the much higher-prevalence group of people who already tested positive once.

## Beyond This Calculator: Where Else Bayes' Theorem Shows Up

The same update rule extends well past diagnostic testing, though this calculator is scoped to the single-test case above. Naive Bayes classifiers (used in spam filtering and text classification) apply the theorem across many independent word-probability features at once. Sequential Bayesian updating — where each posterior becomes the next prior as more evidence arrives — underlies A/B testing bandits, Kalman filters, and financial risk models that revise default probabilities as new data comes in. All of it is the same core formula above, just applied repeatedly or across more variables.

## Related Calculators

This same base-rate effect shows up in the [binomial distribution calculator](/calculators/binomial-distribution-calculator) when modeling repeated independent trials. To check a single test's raw accuracy numbers, or work the confusion-matrix math by hand, see the [standard deviation calculator](/calculators/standard-deviation-calculator) for the underlying variability in a sample.

## Frequently asked questions

### What is Bayes Theorem?

Bayes Theorem is a mathematical formula that calculates the updated probability of a hypothesis (posterior probability) based on prior knowledge and new empirical evidence.

### What is the mathematical formula for Bayes Theorem?

P(A|B) = [P(B|A) × P(A)] / P(B), where P(A|B) is the posterior probability, P(B|A) is the likelihood, P(A) is the prior probability, and P(B) is the marginal probability.

### What is the Base Rate Fallacy in probability?

The Base Rate Fallacy occurs when people ignore the underlying prevalence (prior probability) of an event, leading to vastly inflated expectations of accuracy when evaluating positive test results for rare conditions.

### How is Bayes Theorem used in medical testing?

It calculates the Positive Predictive Value (PPV) — the probability that a patient with a positive test result actually has the disease, factoring in test sensitivity, specificity, and disease prevalence.

### Why isn't a 99%-accurate test 99% reliable for a rare disease?

Because "99% accurate" describes sensitivity and specificity, not the chance a positive result is correct. When the disease is rare, the healthy population is so much larger that even a 1% false-positive rate on it produces more false alarms than true detections — that's the base rate fallacy in action.

### What's the difference between sensitivity and PPV?

Sensitivity asks "if someone has the condition, how likely is a positive test?" PPV asks the reverse question a patient actually cares about: "given a positive test, how likely is the condition?" The two are only close together when the condition is common.

### Does this calculator support Naive Bayes classification or spam filtering?

No — this tool solves the single-test diagnostic case (one prior, one sensitivity, one false-positive rate). Naive Bayes classifiers apply the same theorem across many features at once, which is a different calculation than what's modeled here.

### What is the difference between Frequentist and Bayesian statistics?

Frequentist statistics treats probability as long-run event frequency without incorporating prior beliefs. Bayesian statistics treats probability as a degree of belief that gets explicitly updated as new evidence arrives, starting from a stated prior.

### Why does confirmatory retesting improve accuracy so much?

Because the first test's posterior probability becomes the second test's prior. Retesting someone who already tested positive means the second test is applied to a much higher-prevalence group than the general population, which sharply raises the second test's PPV.

### How is Bayes Theorem applied in financial risk management?

Financial institutions use the same sequential-updating idea to adjust credit default probabilities and portfolio risk models as new earnings or macroeconomic data arrive — each update's posterior becomes the next update's prior.

## Related concepts

- **Law of Total Probability** — A fundamental rule relating marginal probabilities to conditional probabilities across all mutually exclusive outcomes.
- **Positive Predictive Value (PPV)** — The probability that subjects with a positive screening test truly have the target condition.
- **Base Rate Fallacy** — The intuition error of judging a positive test result by the test's accuracy alone, ignoring how rare the underlying condition is.

## Related guides

- [Standard Deviation Guide: Measure Data Spread Clearly](https://dothecalculation.com/blog/math/standard-deviation-explained) — Understand variance, population vs sample formulas, and data spread with worked examples tied to the live DTC standard deviation calculator.

## Related calculators

- [Binomial Distribution Probability Calculator](https://dothecalculation.com/calculators/binomial-distribution-calculator) — Compute binomial probability mass function, cumulative distribution, mean, and variance instantly with this free statistics calculator.
- [Matrix Algebra & Linear Equations Solver](https://dothecalculation.com/calculators/matrix-solver) — Calculate determinants, inverses, and transposes, and solve 2×2 or 3×3 systems of linear equations instantly with this free matrix algebra tool.
- [Bond Yield Calculator](https://dothecalculation.com/calculators/bond-yield-calculator) — Estimate bond yield to maturity, current yield, and Macaulay and modified duration to gauge interest rate sensitivity risk.
- [Scientific Calculator](https://dothecalculation.com/calculators/scientific-calculator) — Calculate advanced arithmetic, trigonometry, logarithms, and exponential functions instantly with this free scientific calculator.
- [Fraction Calculator](https://dothecalculation.com/calculators/fraction-calculator) — Add, subtract, multiply, divide, and simplify fractions instantly with this free step-by-step online fraction calculator tool.
- [Triangle Calculator](https://dothecalculation.com/calculators/triangle-calculator) — Calculate triangle area, perimeter, and semi-perimeter from three side lengths using Heron's formula with this free, step-by-step geometry calculator.

---

_This calculator is for educational and planning purposes. Verify calculations manually for critical medical, clinical, or diagnostic decisions — this tool does not replace clinical judgment._

---

_Source: [Do The Calculation](https://dothecalculation.com/calculators/bayes-theorem-calculator). Quote freely with attribution and a link to this page._
