Bayes' Theorem Examples in Math

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Bayes' Theorem.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in Math.

Concept Recap

Bayes' theorem gives the posterior probability of a hypothesis given evidence: P(HE)=P(EH)P(H)P(E)P(H|E) = \frac{P(E|H) \cdot P(H)}{P(E)}.

Start with a prior belief, then reweight it by how likely the evidence is under each hypothesis.

Read the full concept explanation →

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

Core idea: Bayes' theorem flips a conditional, turning P(EH)P(E|H) and a prior P(H)P(H) into the posterior P(HE)P(H|E).

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

Sense of Study hint: Ask: Am I given P(EH)P(E|H) and a prior, and asked for the flipped P(HE)P(H|E)?

Worked Examples

Example 1

medium
Email spam filter: P(spam)=0.3P(\text{spam})=0.3. The word 'free' appears in 80% of spam emails and 10% of legitimate emails. An email contains 'free'. Find P(spamfree)P(\text{spam}|\text{free}) using Bayes' theorem.

Answer

P(spamfree)0.774P(\text{spam}|\text{free}) \approx 0.774. There's a 77.4% chance the email is spam.

First step

1
Prior: P(spam)=0.3P(\text{spam})=0.3, P(legit)=0.7P(\text{legit})=0.7

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

SetupKey insightWhy it worksCommon pitfallConnection

Unlock answer keys One Family plan — every worked solution, all subjects

Example 2

hard
Drug testing: P(user)=0.05P(\text{user})=0.05. Test sensitivity P(+user)=0.99P(+|\text{user})=0.99. Specificity P(non-user)=0.95P(-|\text{non-user})=0.95 (so P(+non-user)=0.05P(+|\text{non-user})=0.05). Find P(user+)P(\text{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(redshiny)P(\text{red}|\text{shiny}).

Example 4

medium
A communication channel sends 0 with probability 0.6 and 1 with probability 0.4. Each bit is flipped with probability 0.1. The receiver sees 1. Find P(sent 1received 1)P(\text{sent 1}|\text{received 1}).

Example 5

medium
A store has 3 suppliers A (50%), B (30%), C (20%). Defect rates: 2%, 4%, 5%. A randomly chosen item is defective. Find P(Bdefective)P(B|\text{defective}).

Example 6

hard
You have three biased coins with P(H)=0.2,0.5,0.9P(H)=0.2,0.5,0.9 chosen uniformly at random, flipped once, lands heads. Find the posterior probability that the chosen coin has P(H)=0.9P(H)=0.9.

Example 7

challenge
You suspect a coin is biased toward heads. Prior: P(biased)=0.1P(\text{biased})=0.1 with P(Hbiased)=0.75P(H|\text{biased})=0.75; otherwise fair. You observe 8 heads in 10 flips. Find the posterior probability the coin is biased.

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

easy
Write out Bayes' theorem and explain each component: P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A)P(A)}{P(B)}.

Example 2

hard
A coin is either fair (p=0.5p=0.5, probability 0.7) or biased (p=0.8p=0.8, probability 0.3). You flip it once and get heads. Update the probability that the coin is biased using Bayes' theorem.

Example 3

easy
State Bayes' theorem for P(HE)P(H\mid E).

Example 4

easy
Are P(AB)P(A\mid B) and P(BA)P(B\mid A) generally equal?

Example 5

easy
Given P(H)=0.5P(H)=0.5, P(EH)=0.8P(E\mid H)=0.8, and P(E)=0.4P(E)=0.4, find P(HE)P(H\mid E).

Example 6

easy
If the prior P(H)=0P(H)=0, what is the posterior P(HE)P(H\mid E) (for any evidence with P(E)>0P(E)>0)?

Example 7

easy
Compute P(E)P(E) by the law of total probability if P(EH)=0.6P(E\mid H)=0.6, P(H)=0.5P(H)=0.5, P(EHc)=0.2P(E\mid H^c)=0.2, P(Hc)=0.5P(H^c)=0.5.

Example 8

easy
In Bayes' theorem, which term is the 'prior'?

Example 9

easy
Which term, P(EH)P(E\mid H) or P(HE)P(H\mid E), is the 'likelihood' in Bayes' theorem?

Example 10

easy
A disease has prior P(D)=0.01P(D)=0.01. A 99%-accurate test still yields many false positives mainly because of what?

Example 11

medium
A test is 90% sensitive (P(+D)=0.9P(+\mid D)=0.9) and the disease prior is P(D)=0.2P(D)=0.2. Also P(+Dc)=0.1P(+\mid D^c)=0.1. Find P(D+)P(D\mid +).

Example 12

medium
Prior P(H)=0.3P(H)=0.3, P(EH)=0.5P(E\mid H)=0.5, P(EHc)=0.25P(E\mid H^c)=0.25. Find P(HE)P(H\mid E).

Example 13

medium
Two factories: A makes 60% of parts with a 5% defect rate; B makes 40% with a 10% defect rate. A part is defective. Find P(Adefective)P(A\mid \text{defective}).

Example 14

medium
A spam filter: 40% of email is spam. 'Free' appears in 80% of spam and 10% of non-spam. An email contains 'free'. Find P(spamfree)P(\text{spam}\mid \text{free}).

Example 15

medium
A box has 70% fair coins (P(H)=0.5P(H)=0.5) and 30% biased coins (P(H)=0.9P(H)=0.9). A drawn coin flips heads. Find P(biasedH)P(\text{biased}\mid H).

Example 16

medium
Prior odds of HH to HcH^c are 1:31:3. The likelihood ratio P(EH)P(EHc)=6\frac{P(E\mid H)}{P(E\mid H^c)}=6. Find the posterior odds, then P(HE)P(H\mid E).

Example 17

medium
A rare disease has prior 0.0010.001. The test is 99% sensitive (P(+D)=0.99P(+\mid D)=0.99) and 95% specific (P(+Dc)=0.05P(+\mid D^c)=0.05). Find P(D+)P(D\mid +).

Example 18

medium
Using the law of total probability, find P(E)P(E) where H1,H2,H3H_1,H_2,H_3 partition the space: priors 0.2,0.3,0.50.2,0.3,0.5 and P(EHi)=0.1,0.4,0.6P(E\mid H_i)=0.1,0.4,0.6.

Example 19

challenge
With three hypotheses, priors 0.2,0.3,0.50.2,0.3,0.5 and likelihoods 0.1,0.4,0.60.1,0.4,0.6 (so P(E)=0.44P(E)=0.44), find P(H2E)P(H_2\mid E).

Example 20

challenge
A test on a disease with prior 0.040.04 has P(+D)=0.95P(+\mid D)=0.95 and P(+Dc)=0.1P(+\mid D^c)=0.1. A patient tests positive TWICE (independent tests). Find P(D++)P(D\mid ++).

Example 21

challenge
Prior P(H)=0.5P(H)=0.5. Evidence EE has P(EH)=0.3P(E\mid H)=0.3 and P(EHc)=0.6P(E\mid H^c)=0.6. After observing EE, is HH more or less likely than before? Compute P(HE)P(H\mid E).

Example 22

medium
A coin is fair with prior 0.50.5 or two-headed with prior 0.50.5. It is flipped once and lands heads. Find P(two-headedH)P(\text{two-headed}\mid H).

Example 23

easy
Given P(H)=0.25P(H)=0.25, P(EH)=0.8P(E|H)=0.8, P(E)=0.5P(E)=0.5. Find P(HE)P(H|E).

Example 24

easy
If P(HE)=0.6P(H|E)=0.6 and P(E)=0.2P(E)=0.2 and P(H)=0.3P(H)=0.3, find P(EH)P(E|H).

Example 25

medium
A weather model says P(rain)=0.2P(\text{rain})=0.2. If it rains, the forecaster predicts rain 90% of the time; if it doesn't, the forecaster predicts rain 20% of the time. The forecaster predicts rain. Find P(rainpredicted rain)P(\text{rain}|\text{predicted rain}).

Example 26

medium
At a school, 30% of students play sports. Among sport-players, 70% own gym shoes; among non-players, 20% own gym shoes. A student owns gym shoes. Find P(plays sportsgym shoes)P(\text{plays sports}|\text{gym shoes}).

Example 27

medium
A jar has 3 fair coins and 1 two-headed coin. A random coin is flipped and lands heads. Find P(two-headedH)P(\text{two-headed}|H).

Example 28

medium
An urn has 3 fair coins and 1 two-headed coin. A random coin is flipped TWICE and lands heads both times. Find P(two-headedHH)P(\text{two-headed}|HH).

Example 29

medium
A patient's prior probability of disease is 10%. A test has sensitivity 80% and specificity 80%. Find P(D+)P(D|+).

Example 30

medium
Express Bayes' theorem in odds form: the posterior odds of HH given EE equal the prior odds times the ____.

Example 31

medium
Prior odds for spam vs not-spam are 1:31:3. The word 'lottery' has likelihood ratio 99 for spam. Find the posterior odds and P(spamlottery)P(\text{spam}|\text{lottery}).

Example 32

medium
In the previous question, find P(Adefective)P(A|\text{defective}).

Example 33

hard
A disease affects 1 in 1000. A test has sensitivity 99% and specificity 99%. Find P(D+)P(D|+).

Example 34

hard
Continuing the previous problem: after one positive test, the prior becomes 0.0902\approx 0.0902. A second independent test (same sensitivity/specificity) also returns positive. Find the updated posterior.

Example 35

hard
A taxi is in a hit-and-run. 85% of city cabs are Green, 15% Blue. A witness identifies a Blue cab and is right 80% of the time. Find P(actually Bluewitness says Blue)P(\text{actually Blue}|\text{witness says Blue}).

Example 36

hard
Two hypotheses have prior odds 1:2 and the evidence has likelihood ratio 5 for H1H_1 over H2H_2. After observing the evidence twice (independent), find the posterior probability of H1H_1.

Example 37

hard
A factory has 4 machines producing equal shares; defect rates 1%, 2%, 3%, 4%. A defective is found. What is P(machine 4defective)P(\text{machine 4}|\text{defective})?

Example 38

challenge
A genetic test for a recessive trait has sensitivity 98%, specificity 97%. Prevalence is 0.5%. After ONE positive, you re-test using a different independent test of sensitivity 95%, specificity 99%, also positive. Find P(carrier+,+)P(\text{carrier}|+,+).

Background Knowledge

These ideas may be useful before you work through the harder examples.

conditional probabilityprobabilitysample space