Bayes' Theorem Calculator
Compute posterior probability P(A|B) from prior P(A), likelihood P(B|A), and total evidence P(B) — or solve for any of the four variables. Includes live prior-to-posterior visualization, natural frequency breakdown, tree diagram, and full reference tables.
| Outcome | Count | Proportion |
|---|
Bayes' theorem updates beliefs in light of evidence
Bayes' theorem answers the question: "Given that I observed B, how likely is A?" The answer depends on three things — how likely A was before I saw anything (the prior), how likely B is if A is true (the likelihood), and how likely B is overall (the evidence). The result is the posterior — the updated probability of A. This is the mathematical foundation of rational belief revision: every new piece of evidence provides an update, and the posterior becomes the prior for the next observation. The same theorem underlies spam filters, medical diagnostics, search engines, machine learning classifiers, and any application where prior beliefs must be combined with observed data.
Confusing P(A|B) with P(B|A) is the base rate fallacy
The single most common error in Bayesian reasoning is assuming P(A|B) = P(B|A). A test with 95% sensitivity (P(B|A) = 0.95) does not mean a positive test implies a 95% chance of disease. When the disease is rare (P(A) = 0.001) and the false-positive rate is 5% (P(B|¬A) = 0.05), a positive test only gives a 1.9% probability of disease — even though the test itself is "95% accurate." The gap between 95% and 1.9% is the base rate fallacy, and it is why screening programmes for rare diseases produce far more false positives than true positives. Bayes' theorem is precisely the tool that corrects this intuition.
Rare priors are hard to overcome with evidence
When the prior probability of A is very small, even strong evidence shifts the posterior only modestly. With P(A) = 0.001, P(B|A) = 0.99, and P(B|¬A) = 0.01, the posterior is only 0.090 — a 90× update, but still less than 10%. This is why a single rare-disease test is rarely diagnostic, and why clinicians often require confirmation with a second independent test. Applying Bayes' theorem twice (with the first posterior as the second prior) compounds the evidence: the posterior after two positive tests is 0.907, which is much more informative. The same logic applies to spam filters, fraud detection, and security screening — one weak signal rarely suffices, but many independent signals compound multiplicatively.
Odds form and likelihood ratios simplify the update
Bayes' theorem is often easier to work with in odds form. If posterior odds = prior odds × likelihood ratio, where the likelihood ratio is P(B|A)/P(B|¬A), the update is a simple multiplication. A likelihood ratio of 10 means the evidence increases the odds by 10×; a likelihood ratio of 0.1 decreases them 10×. This form appears everywhere in medical literature (sensitivity/(1−specificity)) and in screening guidelines. Working in odds also avoids the awkward P(B) computation: you never need to compute the marginal evidence explicitly. The trade-off is that odds are less intuitive than probabilities for many people, but for repeated updates, odds are the natural language of Bayes.
How to Use This Calculator
Bayes' theorem links four probabilities — the prior, the likelihood, the evidence, and the posterior. Pick what to solve for, and enter the other three.
1. Choose what to solve for
Select P(A|B), P(B|A), P(A), or P(B) from the toggle. The calculator rearranges P(A|B) = P(B|A)·P(A)/P(B) for whichever variable you pick.
2. Use presets for common scenarios
Presets span classic Bayes scenarios: a disease test with 95% sensitivity and 10% prevalence, a rare disease with 1-in-1000 prevalence, a perfect test, and a weak test. Click any preset to load it.
3. Compute P(B) from first principles
If you do not know P(B) directly, use the helper panel: enter P(B|¬A) (the false positive rate) and the calculator computes P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A) using the law of total probability. Click "Apply" to feed the result into the main field.
4. Read the result and the prior→posterior comparison
The result card shows the posterior probability alongside a two-row bar chart showing how the prior updated to the posterior — so you can see the magnitude of the update directly. The verdict classifies the posterior from very unlikely to very likely.
5. Check the tree diagram
The tree shows all four joint outcomes: A∩B, A∩¬B, ¬A∩B, and ¬A∩¬B, with their joint probabilities. The posterior P(A|B) is the ratio of A∩B to the total "observed B" mass (A∩B + ¬A∩B).
6. Switch to Advanced for depth
Advanced mode adds a chart of posterior vs prior across the full range, a natural frequency table showing expected counts per 10,000 people, a sensitivity panel, and companion metrics including the likelihood ratio and Bayes factor.
What This Tool Offers
Built around Bayes' theorem P(A|B) = P(B|A)·P(A)/P(B), the foundation of probabilistic reasoning.
Four-way solving
Solve for the posterior, likelihood, prior, or evidence. All four algebraic rearrangements are exact.
Live probability tree
A full tree showing the A vs ¬A split, the B vs ¬B split under each branch, all four joint probabilities, and the posterior computed from the ratio A∩B / P(B).
Prior → posterior visualization
A two-row comparison bar on the result card shows the magnitude of the belief update at a glance, along with the update factor P(A|B)/P(A).
Law-of-total-probability helper
Enter P(B|¬A) directly and the panel computes P(B) = P(B|A)·P(A) + P(B|¬A)·P(¬A), then applies it to the main field with one click.
Natural frequency table
Advanced mode shows expected counts per 10,000 people — a far more intuitive way to see why rare diseases produce so many false positives (e.g., 95 true positives vs 900 false positives).
Full reference material
Odds-form Bayes, likelihood ratio interpretation, common diagnostic test parameters by domain, and a complete FAQ on base rate fallacy and practical applications.
Reference Tables
Likelihood ratio interpretation, typical diagnostic test parameters, and the complete variable reference.
Likelihood Ratio (LR) Interpretation
The likelihood ratio LR = P(B|A)/P(B|¬A) measures how much evidence B favors A over ¬A. It multiplies the prior odds to produce the posterior odds.
| LR value | Interpretation | Effect on odds | Example |
|---|---|---|---|
| LR > 10 | Strong evidence for A | Odds increase > 10× | Positive result of a highly specific test |
| LR 5–10 | Moderate evidence for A | Odds increase 5–10× | Typical positive result of a good test |
| LR 2–5 | Weak evidence for A | Odds increase 2–5× | Suggestive but not conclusive observation |
| LR 0.5–2 | Barely diagnostic | Odds change < 2× | Weak or ambiguous evidence |
| LR 0.2–0.5 | Weak evidence against A | Odds decrease 2–5× | Suggestive negative result |
| LR 0.1–0.2 | Moderate evidence against A | Odds decrease 5–10× | Typical negative result of a good test |
| LR < 0.1 | Strong evidence against A | Odds decrease > 10× | Negative result of a highly sensitive test |
Common Diagnostic Test Parameters
Typical values for medical and screening tests. Sensitivity = P(B|A); specificity = 1 − P(B|¬A); false positive rate = P(B|¬A).
| Test / scenario | Sensitivity | Specificity | Prevalence P(A) | PPV at this prevalence |
|---|
Variable Reference
| Symbol | Meaning | Range | Typical values |
|---|---|---|---|
| P(A) | Prior probability of A | 0–1 | 0.001 (rare) to 0.50 (common) |
| P(¬A) | Prior probability of not-A | 0–1 | = 1 − P(A) |
| P(B|A) | Likelihood: probability of B given A | 0–1 | 0.90–0.99 for good tests (sensitivity) |
| P(B|¬A) | Probability of B given not-A | 0–1 | 0.01–0.10 (false positive rate) |
| P(B) | Evidence: total probability of B | 0–1 | = P(B|A)·P(A) + P(B|¬A)·P(¬A) |
| P(A|B) | Posterior probability of A given B | 0–1 | PPV in diagnostic testing |
| LR | Likelihood ratio P(B|A)/P(B|¬A) | 0–∞ | > 10 strong, < 0.1 strong against |
| BF | Bayes factor (same as LR for simple hypotheses) | 0–∞ | = LR when comparing two simple hypotheses |
| Odds(A) | Odds of A: P(A)/P(¬A) | 0–∞ | = prior odds, prior to evidence |
What Does Bayes' Theorem Measure?
Bayes' theorem is the mathematical rule for updating a probability estimate when new evidence arrives. It says that the probability of A given B equals the probability of B given A, multiplied by the prior probability of A, divided by the total probability of B. In plain terms: your belief in A after seeing B depends on how plausible A was to begin with, how likely B is if A is true, and how likely B is in general. This is the formal foundation of probabilistic reasoning — every time you see evidence and adjust a belief, you are (implicitly or explicitly) applying Bayes' theorem. It is used in medical diagnosis, spam filtering, machine learning, forensic science, and any domain where uncertain observations must be combined with prior knowledge.
Bayes' Theorem Formula
The defining relationship is a single equation:
where:
P(B|A) is the likelihood of B given A
P(B) is the total probability of observing B
P(A|B) is the posterior probability of A given B
The denominator P(B) is computed via the law of total probability:
Rearranged to solve for the other three quantities:
P(A) = P(A|B) · P(B) / P(B|A)
P(B) = P(B|A) · P(A) / P(A|B)
In odds form, which is often easier to work with for repeated updates:
where the likelihood ratio LR = P(B|A) / P(B|¬A), and:
Posterior odds = P(A|B) / P(¬A|B)
Bayes' Theorem Variables
| Symbol | Meaning | Notes |
|---|---|---|
| P(A) | Prior probability | Initial belief before evidence |
| P(¬A) | Probability of complement | = 1 − P(A) |
| P(B|A) | Likelihood | Probability of B if A is true (sensitivity) |
| P(B|¬A) | False positive rate | = 1 − specificity |
| P(B) | Evidence | Total probability of B across all states |
| P(A|B) | Posterior | Updated probability of A given B (PPV) |
| LR | Likelihood ratio | = P(B|A)/P(B|¬A); the evidence multiplier |
How Each Variable Affects the Posterior
The posterior P(A|B) is proportional to the product of the likelihood and the prior, and inversely proportional to the evidence. Doubling the prior doubles the numerator and therefore (if P(B) is fixed) roughly doubles the posterior. Doubling the likelihood has the same effect. Increasing the evidence P(B) reduces the posterior — a rare observation B is more informative than a common one, because it is more surprising and therefore more indicative when it does occur. This inverse relationship is why "surprising evidence" is powerful: a test result that would almost never happen by chance provides a much stronger update than one that happens frequently.
The most important insight is that the posterior is often very different from the likelihood. Even a highly sensitive test (P(B|A) = 0.95) can produce a low posterior (P(A|B) = 0.05) if the prior is small (P(A) = 0.001) and the false positive rate is non-negligible. The ratio P(B|A)/P(B|¬A) — the likelihood ratio — is what determines how much the prior is shifted. When LR > 1, the posterior is higher than the prior; when LR < 1, the posterior is lower. When LR = 1, the evidence is uninformative — the posterior equals the prior, no matter what the prior is.
Bayes' Theorem Examples
P(B) = 0.95 × 0.10 + 0.10 × 0.90 = 0.095 + 0.09 = 0.185
P(A|B) = 0.95 × 0.10 / 0.185 = 0.095 / 0.185 = 0.5135
(A positive test raises the probability from 10% to 51% — a 5.1× update)
P(B) = 0.99 × 0.001 + 0.05 × 0.999 = 0.00099 + 0.04995 = 0.05094
P(A|B) = 0.99 × 0.001 / 0.05094 = 0.0194
(A positive test raises the probability only to ~1.9% — base rate fallacy in action)
P(B) = 0.999 × 0.10 + 0.01 × 0.90 = 0.0999 + 0.009 = 0.1089
P(A|B) = 0.999 × 0.10 / 0.1089 = 0.9173
(Near-perfect test gives high PPV — the false positive rate is the critical parameter)
P(B|A) = P(A|B)·P(B)/P(A) = 0.50 × 0.30 / 0.10 = 1.50 (impossible — input inconsistent)
Second test: same parameters, using 0.5135 as prior
P(B) = 0.95 × 0.5135 + 0.10 × 0.4865 = 0.4878 + 0.0487 = 0.5365
P(A|B₂) = 0.95 × 0.5135 / 0.5365 = 0.9095
(Two independent positives give 91% — Bayesian updates compound)
Frequently Asked Questions
The base rate fallacy is the tendency to ignore the prior probability (base rate) when evaluating evidence, focusing only on the likelihood. A classic example: a disease affects 1 in 1,000 people. A test has 99% sensitivity and 5% false positive rate. A patient tests positive. Most people, including many doctors, intuitively say the patient probably has the disease — 99% accuracy is very high. But Bayes' theorem says the probability is only 1.9%. The reason: of 1,000 people, 1 has the disease and tests positive (1 true positive), but 50 healthy people also test positive (5% of 999). So 51 positive tests, but only 1 is a true positive — 1/51 ≈ 1.9%. The base rate (0.1%) dominates because the disease is rare. This is why Bayes' theorem is so important in medicine: it corrects for the intuitive over-reliance on test accuracy alone.
They are different conditional probabilities, and confusing them is the source of the base-rate fallacy. P(A|B) is "the probability of A given B" — in a diagnostic test, the probability that you have the disease given a positive test (the positive predictive value). P(B|A) is "the probability of B given A" — the probability that you test positive given that you have the disease (the sensitivity). The two are related by Bayes' theorem but are not equal in general. A test with 99% sensitivity can have less than 2% PPV if the disease is rare. Conversely, a test with only 50% sensitivity can have high PPV if the disease is common. The relationship is: P(A|B) = P(B|A) · P(A) / P(B), and the two become equal only when P(A) = P(B) — that is, when the prior equals the marginal evidence, which happens when A and B are independent.
Apply Bayes' theorem sequentially: compute the posterior P(A|B₁) from the first observation, then use that posterior as the prior for the second observation. The result after all observations is the same as a single application with the joint likelihood. In odds form this becomes especially simple: posterior odds = prior odds × LR₁ × LR₂ × ... × LRₙ, where each LRᵢ is the likelihood ratio for the i-th observation. This multiplicative form is the basis of naïve Bayes classifiers in machine learning, spam filters, and any system that must combine evidence from multiple independent sources. The critical assumption is conditional independence: each observation must be independent of the others given A. If they are correlated (e.g., the same test repeated twice), the update must account for that correlation, and the multiplicative form overstates the evidence.
This is the law of total probability. Every observation B can occur in exactly one of two ways: either A is true and B occurs (probability P(B|A)·P(A)), or A is false and B occurs (probability P(B|¬A)·P(¬A)). Since these are mutually exclusive and exhaustive, the total probability of B is their sum. This is the key step that allows Bayes' theorem to be applied without knowing P(B) directly: you only need to know P(B|A), P(B|¬A), and P(A) — three quantities that are often available from published studies or domain knowledge. The formula extends naturally to more than two hypotheses: if there are k mutually exclusive hypotheses H₁, ..., Hₖ, then P(B) = Σ P(B|Hᵢ)·P(Hᵢ). This is what makes Bayes' theorem so powerful in practical settings, where the marginal evidence is rarely directly observable.
The likelihood ratio LR = P(B|A)/P(B|¬A) measures how much more likely the observation B is if A is true compared to if A is false. When LR > 1, B is evidence for A; when LR < 1, B is evidence against A; when LR = 1, B is uninformative. In odds form, Bayes' theorem becomes posterior odds = prior odds × LR, which makes the update a simple multiplication. LR is widely used in medical diagnostics and clinical epidemiology: a test's likelihood ratio is often reported instead of (or in addition to) its sensitivity and specificity because it combines both into a single number and can be applied to any prior. A test with LR = 10 is a strong positive test (raises odds by 10×); LR = 0.1 is a strong negative test (lowers odds by 10×). LR does not depend on the prior — it is a property of the evidence alone — which is why it is such a useful summary.
Bayes' theorem is the foundation of probabilistic machine learning. Naïve Bayes classifiers — widely used for text classification, spam filtering, and sentiment analysis — assume features are conditionally independent given the class label and combine the per-feature likelihoods multiplicatively. Bayesian networks generalize this to arbitrary dependency structures between variables, giving compact graphical representations of joint distributions. Bayesian inference for parameter estimation uses the same theorem with parameters as A and data as B: the posterior over parameters is proportional to the likelihood times the prior, and this posterior is used for prediction and uncertainty quantification. Gaussian processes, variational autoencoders, Bayesian optimization, and probabilistic graphical models all have Bayes' theorem at their core. The main computational challenge — computing P(B) — is what makes exact Bayesian inference hard, and this is why approximate methods like MCMC and variational inference are so important in practice.
P(A|B) is undefined when P(B) = 0 — you cannot condition on an event that never occurs. This is a mathematical restriction: the conditional probability P(A|B) is defined only when P(B) > 0. In practical terms, if you know that B never happens (say, a test that never produces positive results), then observing B is impossible, and the question "what is the probability of A given B?" has no meaning. In some advanced applications (e.g., continuous probability), you can extend the definition using conditional expectation or measure-theoretic regular conditional probabilities, but the fundamental constraint remains: you can only update on evidence that has nonzero probability. In the calculator, this is enforced by requiring P(B) > 0.
Variables
| Symbol | Quantity | Unit |
|---|---|---|
| P(A|B) | Posterior probability | |
| P(B|A) | Likelihood | |
| P(A) | Prior probability | |
| P(B) | Evidence probability |
What it means
Bayes’ theorem is a fundamental rule in probability theory that describes how to update the probability of a hypothesis (A) based on new evidence (B). It states that the posterior probability P(A|B) is proportional to the likelihood P(B|A) times the prior P(A), normalised by the marginal probability P(B). This theorem is the foundation of Bayesian statistics, which incorporates prior knowledge and updates beliefs as data accumulate. It is widely used in medical diagnosis (interpreting test results), in spam filtering, in machine learning (Naïve Bayes classifiers), and in scientific inference. Understanding Bayes’ theorem enables critical thinking about conditional probabilities and is essential for data‑driven decision making in many fields, including artificial intelligence and epidemiology.
Worked example
Bayes' Theorem – Two Examples
Real‑World| Parameter | Value |
|---|---|
| P(A) (disease) | 0.10 |
| P(B) (positive test) | 0.20 |
| P(B|A) | 0.80 |
| Parameter | Value |
|---|---|
| P(A) | 0.25 |
| P(B) | 0.35 |
| P(B|A) | 0.65 |
Common mistakes
- Prior probability P(A): The probability of event A before considering evidence B – do not ignore it.
- Likelihood P(B|A): The probability of observing B given A – not the same as P(A|B).
- Denominator P(B): The total probability of B – must be non‑zero.
- Independence: If A and B are independent, P(A|B)=P(A) – Bayes still holds.
- Applications: Used in diagnostic tests, machine learning, and updating beliefs.
Applications
Bayes' theorem provides a way to update the probability of a hypothesis based on new evidence, using prior knowledge and the likelihood of the evidence. This theorem is fundamental in statistics, machine learning, and decision science. Engineers use it in fault diagnosis, signal detection, and reliability analysis. In medicine, it informs diagnostic test interpretation. In artificial intelligence, it underpins Bayesian networks and spam filtering. In finance, it updates risk estimates. By applying Bayes' theorem, professionals can systematically incorporate new information, reduce uncertainty, and make better decisions under incomplete knowledge. It is a cornerstone of Bayesian inference, enabling the combination of expert opinion with data. Understanding this theorem is essential for anyone working with uncertainty and predictive modelling.
- Diagnostic testing and medical decision‑making
- Machine learning – Bayesian classifiers and spam filtering
- Reliability engineering – updating failure probabilities
- Signal detection and pattern recognition
- Risk assessment and financial forecasting
Related calculators · Probability Distributions
Recently updated formulas
Suggest an improvement
Found a mistake? Have a better example? Let us know.
You may send up to 3 suggestions per 24 hours.