Bayes' Theorem Calculator

Interactive Bayes' theorem calculator. Compute conditional probabilities from P(A), P(B|A), P(B|¬A) or explore diagnostic test scenarios with prevalence, sensitivity and specificity, plus step-by-step explanations.

Model two events A and B. Enter a prior probability for A and the likelihoods P(B | A) and P(B | ¬A). The calculator applies Bayes' theorem to compute the posterior P(A | B) and related probabilities.

You can enter probabilities (0–1) or percentages (0–100); values above 1 are treated as percentages.

How to Use This Calculator

Toggle between the general probability mode for abstract events (A and B) and diagnostic test mode for condition/test scenarios. Set the relevant inputs and click Calculate. Inputs accept probabilities (0–1) or percentages (0–100).

Results show the posterior probability, supporting KPI rows, and, when applicable, a frequency table calibrated to 10,000 cases so you can see how the numbers behave in context.

Methodology

The calculator implements Bayes' theorem numerically. It normalizes all inputs to [0,1], derives the evidence probability, and updates the prior into the posterior. Diagnostic mode builds on the same math while also computing sensitivity- and specificity-based post-test values and a frequency table.

Full original guide (expanded)

1. General probability mode

Model two events \( A \) and \( B \). Specify a prior probability for \( A \) and the likelihoods \( P(B \mid A) \) and \( P(B \mid \neg A) \). The calculator uses Bayes' theorem to compute \( P(A \mid B) \), \( P(\neg A \mid B) \), and related quantities.

You can enter values either as probabilities (0–1) or percentages (0–100). Values greater than 1 are automatically interpreted as percentages and divided by 100.

All intermediate values are clipped to the range [0, 1] for stability.

The general mode reports the prior \( P(A) \), the complement \( P(\neg A) \), the evidence probability \( P(B) \), the posterior \( P(A \mid B) \), the complement \( P(\neg A \mid B) \), and the complement \( P(\neg B) \).

Formula: \( P(A \mid B) = \dfrac{P(B \mid A) P(A)}{P(B \mid A) P(A) + P(B \mid \neg A) P(\neg A)} \).

2. Diagnostic test mode

Model a binary diagnostic test or classifier: a condition \( D \) (disease, fraud, defect) and a test outcome (+/–). Enter prevalence \( P(D) \), sensitivity \( P(+\mid D) \), and specificity \( P(-\mid \neg D) \). The calculator computes \( P(D \mid +) \), \( P(D \mid -) \), and a frequency table for a notional population of 10,000.

As above, you can use probabilities (0–1) or percentages (0–100); values above 1 are treated as percentages.

The frequency table shows rounded counts for true positives, false positives, true negatives, and false negatives. These counts illustrate how the sensitivity, specificity, and prevalence affect the practical number of cases out of 10,000.

Bayes' theorem in formula form

Bayes' theorem connects a prior probability \( P(A) \), a likelihood \( P(B \mid A) \), and the marginal probability of the evidence \( P(B) \) to produce the posterior probability \( P(A \mid B) \):

\[ P(A \mid B) = \frac{P(B \mid A) \, P(A)}{P(B)} \] \[ P(B) = P(B \mid A) P(A) + P(B \mid \neg A) P(\neg A). \]

The calculator implements these relationships numerically. You provide \( P(A) \), \( P(B \mid A) \), and \( P(B \mid \neg A) \). It computes \( P(B) \) and finally \( P(A \mid B) \) and \( P(\neg A \mid B) \).

Diagnostic tests: prevalence, sensitivity, and specificity

In diagnostic testing, Bayes' theorem often appears in terms of:

  • Prevalence \( P(D) \): baseline probability of the condition.
  • Sensitivity \( P(+ \mid D) \): probability the test is positive when the condition is present.
  • Specificity \( P(- \mid \neg D) \): probability the test is negative when the condition is absent.

From these inputs we obtain:

\[ P(+) = P(+ \mid D) P(D) + P(+ \mid \neg D) P(\neg D) \] with \[ P(+ \mid \neg D) = 1 - \text{specificity}. \] \[ P(D \mid +) = \frac{P(+ \mid D) P(D)}{P(+)}, \quad P(D \mid -) = \frac{P(- \mid D) P(D)}{P(-)}. \]

These posterior probabilities are often called positive predictive value (PPV) and negative predictive value (NPV).

Worked example – email spam filter

Suppose that in your email inbox about \( 20\% \) of emails are spam \( (A) \). Your spam filter flags \( 90\% \) of spam emails as spam \( (P(B \mid A) = 0.9) \) and incorrectly flags \( 5\% \) of genuine emails as spam \( (P(B \mid \neg A) = 0.05) \). What is the probability that an email is spam given that it is flagged as spam?

  • \( P(A) = 0.2 \), so \( P(\neg A) = 0.8 \).
  • \( P(B) = 0.9 \cdot 0.2 + 0.05 \cdot 0.8 = 0.18 + 0.04 = 0.22 \).
  • \( P(A \mid B) = 0.9 \cdot 0.2 / 0.22 \approx 0.818 \).

So about \( 81.8\% \) of emails that are flagged as spam really are spam. Enter these values in the general probability mode to reproduce the result.

Interpreting probabilities vs percentages

Many textbooks use probabilities between 0 and 1, while practitioners often think in percentages. This tool accepts either format and standardises internally:

  • Inputs \( x \) with \( 0 \le x \le 1 \) are treated as probabilities.
  • Inputs \( x \) with \( 1 < x \le 100 \) are treated as percentages and divided by 100.
  • Values outside these ranges trigger an error to avoid silent mistakes.

Common pitfalls and modelling caveats

  • Base rate neglect: Ignoring low prevalence can lead to overconfident interpretations of a positive test. Bayes' theorem makes the role of the base rate explicit.
  • Conditional independence: In many multi-symptom or multi-test settings, naive applications of Bayes' theorem assume independence that may not hold.
  • Mis-specified sensitivity and specificity: Real-world tests may perform differently in subgroups than in the study sample. Using headline sensitivity/specificity numbers outside their original context can be misleading.
  • Discrete vs continuous models: This calculator is intended for simple binary cases. For continuous measurements and complex models, a full Bayesian workflow with appropriate software is recommended.

Frequently asked questions

What is the intuitive meaning of Bayes' theorem?

Informally, Bayes' theorem says: posterior = likelihood × prior, rescaled. You start with a prior belief about \( A \), then see evidence \( B \) that is more or less compatible with \( A \) than with \( \neg A \). The theorem tells you exactly how to update your belief about \( A \) in light of this evidence.

Why are my post-test probabilities lower than I expected?

This usually happens when the prevalence is low. Even with a very accurate test, most positive results may still be false positives if the condition is rare. The diagnostic test mode and frequency table make this effect visible in concrete numbers.

Can I use this for non-medical problems?

Absolutely. Bayes' theorem applies to any situation with prior probabilities and new evidence: credit scoring, fraud detection, machine learning classifiers, quality control, and more. The general mode is deliberately abstract so you can map your own \( A \) and \( B \) to the inputs.

How should I document a Bayes' theorem calculation in a report?

Clearly state your assumptions, including how you chose the prior or prevalence, where the sensitivity and specificity figures come from, and how the evidence \( B \) was measured. Show the key intermediate steps – such as \( P(B) \) and the exact formula for \( P(A \mid B) \) – so that colleagues can replicate the calculation independently.


Audit: Complete
Formula (LaTeX) + variables + units
This section shows the formulas used by the calculator engine, plus variable definitions and units.
Formula (extracted LaTeX)
\[P(A \mid B) = \frac{P(B \mid A) \, P(A)}{P(B)}\]
P(A \mid B) = \frac{P(B \mid A) \, P(A)}{P(B)}
Formula (extracted LaTeX)
\[P(B) = P(B \mid A) P(A) + P(B \mid \neg A) P(\neg A).\]
P(B) = P(B \mid A) P(A) + P(B \mid \neg A) P(\neg A).
Formula (extracted LaTeX)
\[P(+) = P(+ \mid D) P(D) + P(+ \mid \neg D) P(\neg D)\]
P(+) = P(+ \mid D) P(D) + P(+ \mid \neg D) P(\neg D)
Formula (extracted LaTeX)
\[P(+ \mid \neg D) = 1 - \text{specificity}.\]
P(+ \mid \neg D) = 1 - \text{specificity}.
Formula (extracted LaTeX)
\[P(D \mid +) = \frac{P(+ \mid D) P(D)}{P(+)}, \quad P(D \mid -) = \frac{P(- \mid D) P(D)}{P(-)}.\]
P(D \mid +) = \frac{P(+ \mid D) P(D)}{P(+)}, \quad P(D \mid -) = \frac{P(- \mid D) P(D)}{P(-)}.
Formula (extracted text)
\[ P(A \mid B) = \frac{P(B \mid A) \, P(A)}{P(B)} \] \[ P(B) = P(B \mid A) P(A) + P(B \mid \neg A) P(\neg A). \]
Formula (extracted text)
\[ P(+) = P(+ \mid D) P(D) + P(+ \mid \neg D) P(\neg D) \] with \[ P(+ \mid \neg D) = 1 - \text{specificity}. \] \[ P(D \mid +) = \frac{P(+ \mid D) P(D)}{P(+)}, \quad P(D \mid -) = \frac{P(- \mid D) P(D)}{P(-)}. \]
Variables and units
  • No variables provided in audit spec.
Sources (authoritative):
Changelog
Version: 0.1.0-draft
Last code update: 2026-01-19
0.1.0-draft · 2026-01-19
  • Initial audit spec draft generated from HTML extraction (review required).
  • Verify formulas match the calculator engine and convert any text-only formulas to LaTeX.
  • Confirm sources are authoritative and relevant to the calculator methodology.
Verified by Ugo Candido on 2026-01-19
Profile · LinkedIn

More probability & Bayesian tools

About this Bayes' theorem tool

This calculator is designed for students, educators, analysts, and engineers who want a transparent, step-by-step implementation of Bayes' theorem for binary events and diagnostic tests, with formulas that can be checked against textbooks or statistical software.

For high-stakes decisions, treat the results as an educational cross-check and confirm them using validated tools and, where appropriate, expert review.

Formulas

Bayes' theorem:

P(A | B) = [P(B | A) × P(A)] / P(B)

P(B) = P(B | A) P(A) + P(B | ¬A) P(¬A)

Diagnostic mode additions:

P(+) = P(+ | D) P(D) + (1 − specificity) P(¬D)

PPV = [P(+ | D) P(D)] / P(+)

NPV = [specificity × P(¬D)] / P(-)

Citations

NIST — Weights and measures — nist.gov · Accessed 2026-01-19

https://www.nist.gov/pml/weights-and-measures

FTC — Consumer advice — consumer.ftc.gov · Accessed 2026-01-19

https://consumer.ftc.gov/

Changelog
  • 0.1.0-draft — 2026-01-19: Initial audit spec draft generated from HTML extraction.
  • Verify formulas match the calculator engine and convert text-only formulas to LaTeX.
  • Confirm sources are authoritative and relevant to the methodology.
Verified by Ugo Candido Last Updated: 2026-01-19 Version 0.1.0-draft
Version 1.5.0