Bayes' Theorem Formula

Bayes' theorem gives the posterior probability of a hypothesis given evidence: P(H|E) = P(E|H) · P(H)/(P(E)).

The Formula

P(A∣B)=P(B∣A)⋅P(A)P(B)

Ask yourself: Am I given P(E∣H) and a prior, and asked for the flipped P(H∣E)?

Quick example

A disease test catches 99% of cases and gives a false positive to 1% of healthy people; 1% of people have the disease. If you test positive, P(disease∣+)≈50% — not 99%, because the disease is rare.

Notation

P(A) is the prior, P(B∣A) is the likelihood, P(A∣B) is the posterior, and P(B) is the total evidence probability.

What this formula means

Bayes' theorem gives the posterior probability of a hypothesis given evidence: P(H∣E)=P(E∣H)⋅P(H)P(E).

Bayes works like a detective weighing suspects. Before any clue, some suspects are more likely than others: the prior. A clue such as muddy boots fits some suspects better than others: the likelihood. Multiply the two for each suspect and rescale so the chances add to 1. A clue that fits a rare suspect perfectly can still point to a common suspect it fits less well.

Formal view

For events A and B with P(B)>0: P(A∣B)=P(B∣A)⋅P(A)P(B) where P(B)=P(B∣A)P(A)+P(B∣Ac)P(Ac) by the law of total probability.

Worked examples

Example 1

medium
Email spam filter: P(spam)=0.3. The word 'free' appears in 80% of spam emails and 10% of legitimate emails. An email contains 'free'. Find P(spam∣free) using Bayes' theorem.
Show solution

Answer

P(spam∣free)≈0.774. There's a 77.4% chance the email is spam.

First step

1.
Prior: P(spam)=0.3, P(legit)=0.7

See the full worked solution + why-it-works coaching

SetupKey insightWhy it worksCommon pitfallConnection

Free: full solutions on 3 topics a day. No card.

Every topic, every day: the Family plan

Example 2

hard
Drug testing: P(user)=0.05. Test sensitivity P(+∣user)=0.99. Specificity P(−∣non-user)=0.95 (so P(+∣non-user)=0.05). Find P(user∣+).

Example 3

medium
A box contains 40% red and 60% blue marbles. Red marbles are 'shiny' 30% of the time; blue marbles are shiny 10% of the time. A drawn marble is shiny. Find P(red∣shiny).

Common mistakes

  • Treating P(H∣E) as equal to P(E∣H) - Bayes flips them, and the prior makes the two differ.
  • Ignoring the base rate (prior) - a rare condition keeps the posterior low even after strong evidence.
  • Using the wrong denominator - P(E) must total over ALL hypotheses (true and false), e.g. true positives plus false positives.

Why this formula matters

Bayes' theorem is how doctors should read test results, how spam filters score emails and how evidence should be weighed in court. Without it people confuse P(E∣H) with P(H∣E): they hear that a test catches 90% of cases and conclude that a positive result means a 90% chance of disease, when for a rare disease it can be about 15%. The theorem forces the key question: how common was this to begin with?

Frequently asked questions

What is the Bayes' Theorem formula?

Bayes' theorem gives the posterior probability of a hypothesis given evidence: P(H∣E)=P(E∣H)⋅P(H)P(E).

How do you use the Bayes' Theorem formula?

Use Bayes' theorem when you are given a conditional in one direction, such as test accuracy P(+∣D), plus a prior or base rate, and asked for the reverse: how likely the cause is given the evidence. Typical settings are medical tests, spam filters, faulty-machine problems and eyewitness reports. If a two-way table of counts is given, read the conditional directly; if the question asks for two events both happening, use the multiplication rule.

What do the symbols mean in the Bayes' Theorem formula?

P(A) is the prior, P(B∣A) is the likelihood, P(A∣B) is the posterior, and P(B) is the total evidence probability.

Why is the Bayes' Theorem formula important in Math?

Bayes' theorem is how doctors should read test results, how spam filters score emails and how evidence should be weighed in court. Without it people confuse P(E∣H) with P(H∣E): they hear that a test catches 90% of cases and conclude that a positive result means a 90% chance of disease, when for a rare disease it can be about 15%. The theorem forces the key question: how common was this to begin with?

What do students get wrong about Bayes' Theorem?

The procedure for bayes' theorem is the easy part; the trap is treating P(H∣E) as equal to P(E∣H). Asking "Am I given P(E∣H) and a prior, and asked for the flipped P(H∣E)?" first is what keeps a correct-looking calculation from being attached to the wrong concept.

What should I learn before the Bayes' Theorem formula?

Before studying the Bayes' Theorem formula, you should understand: conditional probability, probability, sample space.