Probability & Combinatorics
Advanced

Bayes Theorem

Reverses conditional probabilities using prior knowledge.

Formula

P(A∣B)=P(B∣A) P(A)P(B)P(A|B) = \frac{P(B|A)\,P(A)}{P(B)}

Variables

P(A)Prior
P(BA)
P(B)Evidence

Example

Core of spam filters and medical testing

How it works

Bayes’ theorem lets you update the probability of a hypothesis A after seeing evidence B. It comes directly from the definition of conditional probability: the chance of A and B together can be written as P(A|B)P(B) or P(B|A)P(A), so rearranging gives the formula. The key idea is that evidence is not interpreted in isolation; it is weighed against how likely that evidence is under different possible causes.

When to use it

Use this when you know how likely some evidence is if a hypothesis is true, but you want the reverse: how likely the hypothesis is given the evidence. It is especially useful in diagnostic testing, classification, fault detection, and any problem with competing explanations.

Worked example, step by step

Suppose 2% of a factory’s widgets are defective. We test a widget using a detector that is 95% accurate for defective items, so P(test + | defective) = 0.95. The false positive rate is 4%, so P(test + | not defective) = 0.04. We want P(defective | test +). Step 1: Find the overall probability of a positive test: P(test +) = P(test + | defective)P(defective) + P(test + | not defective)P(not defective) P(test +) = (0.95)(0.02) + (0.04)(0.98) P(test +) = 0.019 + 0.0392 = 0.0582 Step 2: Apply Bayes’ theorem: P(defective | test +) = [P(test + | defective)P(defective)] / P(test +) P(defective | test +) = (0.95 × 0.02) / 0.0582 P(defective | test +) = 0.019 / 0.0582 ≈ 0.3265 Final answer: P(defective | test +) ≈ 0.327, or about 32.7%.

Common mistakes to avoid

  • Confusing P(A|B) with P(B|A): the order matters and the two are usually not equal
  • Forgetting to calculate P(B) as the total probability across all ways B can happen
  • Ignoring the prior probability of A, which can strongly change the result even with strong evidence

Did You Know?

Bayes theorem underpins much of modern statistics and machine learning.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026