In the previous post we learned conditional probability: how the chance of an event changes once we know that another event has happened. Bayes’ theorem takes the very next step. It lets us reverse a conditional probability, so that from an effect we can work backwards to its most likely cause. In this post we will build the idea from scratch, understand the intuition, learn to read a probability tree, and then solve nine practice questions from easy to advanced. Every solution comes with a tree in which the path we need is circled.
What is Bayes’ Theorem?
Definition
Bayes’ theorem gives the probability that a particular cause was responsible for an observed effect. If an event A is known to have happened, and it could have happened through several different routes E1, E2, …, En, Bayes’ theorem tells us the probability that it happened through a specific route Ei.
Conditional probability usually answers a forward question: “If this cause is present, how likely is the effect?” Bayes’ theorem answers the backward question: “The effect has been observed. How likely is it that this particular cause produced it?”
Here are a few everyday forms of this backward question:
- A product is found defective. What is the chance it came from Machine 2?
- A medical test is positive. What is the chance the person really has the disease?
- A student answered correctly. What is the chance the student copied the answer?
- A parcel is lost. What is the chance the second post office lost it?
Conditions Necessary for Bayes’ Theorem
Bayes’ theorem in its general form works only when the “causes” are set up properly. Check these conditions before you use it:
- Mutually exclusive causes. The events E1, E2, …, En cannot happen together. Exactly one of them is responsible.
- Exhaustive causes. Together they cover every possibility: E1 ∪ E2 ∪ … ∪ En = whole sample space. This means P(E1) + P(E2) + … + P(En) = 1.
- Non-zero probabilities. P(Ei) > 0 for every cause, and the observed event has P(A) > 0 (we cannot divide by zero).
- Known inputs. We know the prior probabilities P(Ei) and the likelihoods P(A | Ei).
- The event A has already happened. The question is always of the type “given that A occurred, find the probability of Ei.”
How to spot a Bayes question
Look for phrases such as “given that”, “it is found that”, “if it is observed that”, “what is the probability that it came from”. The result is known; the cause is the unknown.
Simple (two-event) form
Start from the multiplication rule of conditional probability. The same event “A and B both happen” can be written in two ways:
P(A ∩ B) = P(A) × P(B | A) and P(A ∩ B) = P(B) × P(A | B)
Both are equal, so P(B) × P(A | B) = P(A) × P(B | A). Dividing by P(B) gives Bayes’ theorem:
P(A | B) =
P(B | A) × P(A)P(B)
General form (several causes)
When the causes E1, E2, …, En satisfy the conditions above, and A is the observed event:
P(Ei | A) =
P(Ei) × P(A | Ei)P(E1)P(A | E1) + P(E2)P(A | E2) + … + P(En)P(A | En)
| Term | Name | Meaning in plain words |
| P(Ei) | Prior | How likely the cause was before we saw the evidence. |
| P(A | Ei) | Likelihood | If this cause is true, how likely is the evidence A? |
| P(A) | Evidence (total probability) | Overall chance of seeing A, through any cause. |
| P(Ei | A) | Posterior | How likely the cause is after we saw the evidence. This is what we want. |
Law of Total Probability (the denominator)
The denominator of Bayes’ theorem is not magic. It is the law of total probability. If E1, …, En are mutually exclusive and exhaustive, then the event A can happen only along one of these routes, so we add up the probability of every route:
P(A) = P(E1) P(A | E1) + P(E2) P(A | E2) + … + P(En) P(A | En)
Each term is “reach the cause, and then produce A”. Adding all such routes gives the total chance of A. So Bayes’ theorem is simply:
P(Ei | A) = probability of the route through Eiprobability of all routes that give A
Intuition for Beginners
Imagine 100 emails. Suppose 20 are spam and 80 are genuine. The word “winner” appears in 15 of the 20 spam emails and in 8 of the 80 genuine emails.
You open an email and see the word “winner”. How likely is it spam?
- Emails containing “winner”: 15 (spam) + 8 (genuine) = 23.
- Of these 23, spam emails are 15.
- So P(spam | “winner”) = 15/23, which is about 65.2%.
That is Bayes’ theorem in action, without any formula. We shrank the world to only those emails that contain the evidence, and then asked what share of that shrunken world belongs to spam. The formula does exactly the same with probabilities instead of counts.
Two ideas to remember
1. Reverse is not equal. P(wet road | rain) is high, but P(rain | wet road) can be low, because a sprinkler or a water tanker can also wet the road. P(A | B) and P(B | A) are different numbers.
2. Start belief, update belief. The prior is your starting belief. The evidence pushes it up or down. The posterior is the updated belief.
How to Read a Probability Tree
A probability tree is a picture of all the ways things can happen. Here is the same spam example drawn as a tree. The first split is the cause (spam or genuine). The second split is the evidence (has the word “winner” or not).
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
Each oval shows the share of all emails that follow that path.
Three simple rules are all you need:
- Multiply along a path. A path means “this happened, and then that happened”, so we multiply the numbers on its branches. The path Spam → has “winner” gives 0.2 × 0.75 = 0.15.
- Add the paths that end in the evidence. Two paths end with “winner”: 0.15 (green) and 0.08 (amber). Total = 0.15 + 0.08 = 0.23. This is the denominator, P(A).
- Circled path ÷ all evidence paths. The circled green path is the one we want to know about. Its share of the evidence is 0.15 ÷ 0.23 = 15/23, the same answer we got by counting.
What do the circles mean in this post?
In every solution below, the solid green circle marks the path we are asked about. The dashed amber circles mark the other paths that also produce the evidence. The green path goes on top of the fraction; the green and amber paths added together go at the bottom. Paths with no circle do not matter, because the evidence did not happen on them.
A 6-Step Recipe to Solve Any Bayes Question
- Name the causes. Define E1, E2, … and check they are mutually exclusive and add up to 1.
- Name the evidence. Define A, the event that is “given” in the question.
- List the inputs. Write the priors P(Ei) and the likelihoods P(A | Ei).
- Draw the tree. Put the priors on the first branches and the likelihoods on the second. Circle the path you want.
- Find P(A). Multiply along each path that gives A, then add those paths (law of total probability).
- Divide. P(Ei | A) = circled path ÷ P(A). Simplify and sanity-check: all posteriors must add up to 1.
Question 1: The Lost Parcel (Three Methods)
Question 1Easy to Medium
A parcel is sent from sender A to receiver B, passing one after the other through two sorting centres. Each centre independently loses an incoming parcel with probability 1/4, regardless of what happens to other parcels. Given that the parcel is lost, find the probability that it was lost at the second centre.
Solution
Understand the question first
The phrase “given that the parcel is lost” is a condition. It tells us the loss has already happened, so we only look at the world in which the parcel is lost. In that world there are two possible culprits: the first centre or the second centre. We want the chance that it was the second one.
Notice that the answer is not simply 1/4. The second centre only ever sees a parcel if the first centre did not lose it.
Method 1: Reduced sample space
The idea: the condition shrinks our world. Instead of dividing by 1 (the whole world), we divide by the probability of the condition.
- Original probability = 1. After the condition, the reduced world has probability P(parcel is lost).
- Find P(lost). The parcel is lost if the first centre loses it, or if the first centre does not lose it and the second does. These two cases cannot happen together, so we add:
P(lost) = P(lost by first) + P(not lost by first and lost by second)
= 1/4 + (3/4)(1/4) = 4/16 + 3/16 = 7/16
Why (3/4)(1/4)? The first centre fails to lose it with probability 3/4, and then the second centre loses it with probability 1/4. “And then” means multiply.
- Favourable probability (the parcel is lost by the second centre): (3/4)(1/4) = 3/16.
- Required probability = favourable ÷ reduced world:
3/167/16 = 3/7
Method 2: Bayes’ theorem
Here we follow the 6-step recipe with the full formula.
- Define the events.
E1 = parcel is lost by the first centre
E2 = parcel is not lost by the first centre, but is lost by the second
E3 = parcel is lost by neither centre
A = the parcel is lost
These three events are mutually exclusive (only one can happen) and exhaustive (one of them must happen).
- Priors (the chance of each event before we use the condition):
P(E1) = 1/4
P(E2) = (3/4)(1/4) = 3/16
P(E3) = (3/4)(3/4) = 9/16
Check: 4/16 + 3/16 + 9/16 = 16/16 = 1
- Likelihoods (if this event happened, how sure are we that A, “lost”, happened?). If E1 or E2 happened, the parcel is certainly lost. If E3 happened, it is certainly not lost:
P(A | E1) = 1, P(A | E2) = 1, P(A | E3) = 0
- Write the formula. We want P(E2 | A):
P(E2 | A) = P(E2) P(A | E2)P(E1) P(A | E1) + P(E2) P(A | E2) + P(E3) P(A | E3)
- Calculate the denominator (this is P(A), by the law of total probability):
(1/4)(1) + (3/16)(1) + (9/16)(0) = 4/16 + 3/16 + 0 = 7/16
The E3 term is zero because on that path the parcel is never lost.
- Calculate the numerator:
P(E2) P(A | E2) = (3/16)(1) = 3/16
- Divide and simplify:
P(E2 | A) = 3/167/16 = 3/7
Method 3: Visual probability tree
Start with Parcel at the top. Three branches leave it, one for each of the mutually exclusive and exhaustive events E1, E2 and E3, with probabilities 1/4, (3/4)(1/4) = 3/16 and (3/4)(3/4) = 9/16. From each event, one more arrow tells us whether the parcel is lost: 1 means lost and 0 means not lost.
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
Lower labels are the indicator of “parcel is lost” (1 = lost, 0 = not lost). Each oval shows path probability × indicator.
- The branches cover everything.
P(E1) + P(E2) + P(E3) = 1/4 + 3/16 + 9/16 = 4/16 + 3/16 + 9/16 = 16/16 = 1
- What the final labels mean. They are the indicator of the event “parcel is lost”: 1 if the parcel is lost, 0 if it is not lost. Multiplying a path by its indicator keeps the path if the parcel is lost and removes it if not.
- Probability that the parcel is lost. Multiply each branch probability by its indicator and add:
P(A) = (1/4)(1) + (3/16)(1) + (9/16)(0) = 4/16 + 3/16 + 0 = 7/16
- Identify the favourable path. The parcel is lost by the second centre only along the middle branch E2. This is the circled green path, with probability 3/16. The dashed amber path (E1) is the other way of losing the parcel.
- Divide. Favourable path ÷ total probability of the condition:
3/167/16 = 3/7
All three methods give the same answer: P(lost by second centre | parcel is lost) = 3/7
Sanity check
The chance that the first centre lost it is (1/4) ÷ (7/16) = 4/7. Then 4/7 + 3/7 = 1, as it must be. The first centre gets the larger share simply because it sees every parcel, while the second centre sees only those that survived the first.
Question 2: The Examination
Question 2Medium
In an examination, an examinee either guesses, copies, or knows the answer to a multiple-choice question with four choices, of which exactly one is correct. The probability that the examinee guesses is 1/3 and the probability that the examinee copies is 1/6. The probability that the answer is correct, given that the examinee copied it, is 1/8. Find the probability that the examinee copied the answer, given that the answer was correct.
Solution
Understand the question first
There are three ways the examinee can produce an answer: guess, copy or know. These are our causes. The evidence is that the answer turned out to be correct. We must look only at correct answers and ask: what share of them came from copying?
The question does not give P(knows) directly. We get it from the fact that the three probabilities must add up to 1.
- Define the events.
G = examinee guesses, C = examinee copies, K = examinee knows the answer
A = the answer is correct
G, C and K are mutually exclusive and exhaustive: the examinee does exactly one of the three.
- Find the missing prior. Since the three add up to 1:
P(K) = 1 − 1/3 − 1/6 = 6/6 − 2/6 − 1/6 = 1/2
- Find the likelihoods (the chance of a correct answer in each way):
Guessing among 4 choices: P(A | G) = 1/4
Copying (given in the question): P(A | C) = 1/8
Knowing the answer: P(A | K) = 1
Now we draw the tree. Priors go on the first branches, likelihoods on the second. The path we need is Copies → Correct, so it is circled in green.
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
Upper labels: prior of each way of answering. Lower labels: chance of being correct or wrong in that way.
- The circled path (numerator). Copies and then correct, so we multiply:
P(C) P(A | C) = (1/6)(1/8) = 1/48
- All paths ending in “Correct” (denominator). A correct answer can come from guessing, copying or knowing, so we add all three paths (green and amber):
(1/3)(1/4) + (1/6)(1/8) + (1/2)(1)
= 1/12 + 1/48 + 1/2
= 4/48 + 1/48 + 24/48 = 29/48
We wrote every fraction over 48 so that they can be added.
- Divide. Writing it as the Bayes formula:
P(C | A) = P(C) P(A | C)P(G) P(A | G) + P(C) P(A | C) + P(K) P(A | K) = 1/4829/48 = 1/29
The 48s cancel. In plain words: if we cut all the correct answers into 29 equal parts, only 1 part comes from copying.
Required probability = 1/29 (about 0.0345)
More Practice Questions (Easy to Advanced)
Try each question on your own first. Then compare your steps and your tree with the solution.
Question 3Beginner
Bag I contains 3 red and 2 blue balls. Bag II contains 1 red and 4 blue balls. A fair coin is tossed: heads means Bag I is chosen, tails means Bag II. One ball is drawn from the chosen bag and it is red. Find the probability that it came from Bag I.
Solution
Understand the question first
We do not know which bag was used (the cause). We only know the ball drawn was red (the evidence). Red balls can come from either bag, so we ask: of all the ways to get a red ball, what share goes through Bag I?
- Events. B1 = Bag I chosen, B2 = Bag II chosen, R = red ball drawn.
- Priors. The coin is fair, so P(B1) = P(B2) = 1/2.
- Likelihoods. Chance of red inside each bag: P(R | B1) = 3/5 (3 red out of 5 balls) and P(R | B2) = 1/5 (1 red out of 5 balls).
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
- The circled path. Bag I and then red: (1/2)(3/5) = 3/10.
- All red paths. The other path that ends in red is Bag II and then red: (1/2)(1/5) = 1/10. So
P(R) = 3/10 + 1/10 = 4/10 = 2/5
- Divide.
P(B1 | R) = 3/104/10 = 3/4
Answer: 3/4 (so Bag II has the remaining 1/4)
Question 4Easy
In a factory, Machine M1 makes 60% of the items and Machine M2 makes the other 40%. Two percent of M1‘s items are defective and 5% of M2‘s items are defective. An item is picked at random and found to be defective. What is the probability that it was made by M2?
Solution
Understand the question first
The causes are the two machines. The evidence is “the item is defective”. Percentages are just probabilities in disguise: 60% = 0.60, 2% = 0.02 and so on. We look only at defective items and ask what share of them came from M2.
- Events. M1, M2 = made by that machine; D = item is defective.
- Priors. P(M1) = 0.60, P(M2) = 0.40.
- Likelihoods. P(D | M1) = 0.02, P(D | M2) = 0.05.
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
- The circled path. Made by M2 and defective: 0.40 × 0.05 = 0.020.
- All defective paths. Add the amber path (M1 and defective): 0.60 × 0.02 = 0.012. So
P(D) = 0.012 + 0.020 = 0.032
- Divide.
P(M2 | D) = 0.020 ÷ 0.032 = 5/8 = 0.625
Answer: 5/8
Notice
M2 makes fewer items (40%) but is more error-prone, so it is responsible for the majority (62.5%) of defective items.
Question 5Medium
A disease affects 1% of a population. A test detects the disease in 95% of people who have it, but also gives a false positive for 5% of healthy people. A randomly chosen person tests positive. What is the probability that this person actually has the disease?
Solution
Understand the question first
The causes are “sick” and “healthy”. The evidence is a positive test. A positive result can come from a sick person (a true positive) or from a healthy person (a false positive). We ask: among everyone who tests positive, what share is really sick?
- Events. S = person is sick, H = person is healthy, T = test is positive.
- Priors. P(S) = 0.01, P(H) = 0.99.
- Likelihoods. P(T | S) = 0.95 (the test catches 95% of sick people), P(T | H) = 0.05 (the false-positive rate).
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
- The circled path. Sick and tests positive: 0.01 × 0.95 = 0.0095.
- All positive paths. The amber path is healthy and tests positive: 0.99 × 0.05 = 0.0495. So
P(T) = 0.0095 + 0.0495 = 0.059
- Divide.
P(S | T) = 0.0095 ÷ 0.059 = 19/118 ≈ 0.161, i.e. about 16.1%
Answer: about 16.1%
Check with counts
Take 10,000 people. 100 are sick and 95 of them test positive. 9,900 are healthy and 495 of them test positive. Total positives = 590, of which only 95 are truly sick: 95/590 ≈ 16.1%. The surprising answer comes from the very low prior (1%): healthy people are so many that their false positives outnumber the true positives.
Question 6Medium
Three factories A, B and C supply 50%, 30% and 20% of the bulbs in a shop. The percentages of defective bulbs from A, B and C are 1%, 2% and 3% respectively. A bulb bought from the shop is defective. Find the probability that it came from factory C.
Solution
Understand the question first
This is Question 4 with three causes instead of two. The evidence is “the bulb is defective”, and it can come from any of the three factories. We look only at defective bulbs and ask what share came from C.
- Events. FA, FB, FC = bulb from that factory; D = bulb is defective.
- Priors. 0.5, 0.3, 0.2 (they add up to 1).
- Likelihoods. P(D | FA) = 0.01, P(D | FB) = 0.02, P(D | FC) = 0.03.
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
- Multiply along each “defective” path.
Through A: 0.5 × 0.01 = 0.005
Through B: 0.3 × 0.02 = 0.006
Through C (circled): 0.2 × 0.03 = 0.006
- Add them to get the denominator. P(D) = 0.005 + 0.006 + 0.006 = 0.017.
- Divide. P(FC | D) = 0.006 ÷ 0.017 = 6/17 ≈ 0.353.
Answer: 6/17
Sanity check
The three posteriors are 5/17 (A), 6/17 (B) and 6/17 (C). They add up to 17/17 = 1, as they should.
Question 7Advanced
A box contains three coins: one is two-headed, one is fair, and one is biased with P(head) = 1/3. A coin is chosen at random and tossed twice. Both tosses show heads. Find the probability that the chosen coin is the two-headed coin.
Solution
Understand the question first
The causes are the three coins. The evidence is a sequence: head on the first toss and head on the second. Each toss is independent once the coin is fixed, so the chance of “HH” with a coin is (chance of head) × (chance of head). We ask which coin is most likely to have produced HH.
- Events. C1 = two-headed coin, C2 = fair coin, C3 = biased coin; HH = both tosses are heads.
- Priors. P(C1) = P(C2) = P(C3) = 1/3.
- Likelihoods. The tosses are independent, so we multiply:
P(HH | C1) = 1 × 1 = 1
P(HH | C2) = (1/2)(1/2) = 1/4
P(HH | C3) = (1/3)(1/3) = 1/9
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
- The circled path. Two-headed coin and HH: (1/3)(1) = 1/3.
- All HH paths.
P(HH) = (1/3)(1) + (1/3)(1/4) + (1/3)(1/9) = 1/3 + 1/12 + 1/27
= (1/3)(1 + 1/4 + 1/9) = (1/3)(49/36) = 49/108
Taking out the common factor 1/3 makes the addition easy: 1 + 1/4 + 1/9 = 36/36 + 9/36 + 4/36 = 49/36.
- Divide.
P(C1 | HH) = 1/349/108 = 36/10849/108 = 36/49
Answer: 36/49 (about 73.5%)
Intuition
Before tossing, the two-headed coin had a prior of only 1/3 (about 33%). Seeing two heads in a row is a lot more likely under the two-headed coin than under the others, so the belief jumps to about 73.5%. More heads would push it even higher.
Question 8Advanced
30% of incoming emails are spam. The word “offer” appears in 60% of spam emails and in 10% of genuine emails. The word “free” appears in 50% of spam emails and in 5% of genuine emails. Assume that, within spam and within genuine emails separately, the two words appear independently. An email contains both words. Find the probability that it is spam.
Solution
Understand the question first
The causes are “spam” and “genuine”. The evidence is a bit more complicated: the email contains both words. Because the two words appear independently inside each type of email, the chance of seeing both is the product of the two individual chances. So the first job is to turn the word percentages into one likelihood for each cause.
- Events. S = spam, N = genuine, W = email contains both words.
- Priors. P(S) = 0.30, P(N) = 0.70.
- Likelihoods (independence lets us multiply the two word probabilities):
P(W | S) = 0.6 × 0.5 = 0.30
P(W | N) = 0.1 × 0.05 = 0.005
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
- The circled path. Spam and both words: 0.30 × 0.30 = 0.09.
- All “both words” paths. The amber path is genuine and both words: 0.70 × 0.005 = 0.0035. So
P(W) = 0.09 + 0.0035 = 0.0935
- Divide. P(S | W) = 0.09 ÷ 0.0935 = 180/187 ≈ 0.963.
Answer: about 96.3%
Why this matters
Each extra piece of evidence multiplies the odds in favour of spam. This is the idea behind the classic “naive Bayes” spam filter.
Question 9Advanced
A parcel travels through three post offices in sequence. Each post office independently loses an incoming parcel with probability 1/5. Given that the parcel is lost, find the probability that it was lost by the third post office.
Solution
Understand the question first
This is Question 1 with one more post office. The condition is “the parcel is lost”. To be lost by the third office, the parcel must first survive the first and the second office, and then be lost by the third. Every extra office the parcel has to survive multiplies the path by 4/5.
- Events. E1, E2, E3 = parcel is lost by the 1st, 2nd, 3rd office respectively; E4 = not lost by any office. A = parcel is lost.
- Priors.
P(E1) = 1/5 = 25/125
P(E2) = (4/5)(1/5) = 20/125
P(E3) = (4/5)(4/5)(1/5) = 16/125
P(E4) = (4/5)3 = 64/125
Check: 25 + 20 + 16 + 64 = 125, so the total is 1
- Likelihoods. P(A | E1) = P(A | E2) = P(A | E3) = 1 and P(A | E4) = 0 (these are the indicator labels on the lower arrows of the tree).
- Circled path we need (numerator)
- Other paths that also give the evidence
- Paths that do not matter now
Lower labels are the indicator of “parcel is lost” (1 = lost, 0 = not lost). Each oval shows path probability × indicator.
- The circled path (lost by the third office) has probability P(E3) × 1 = 16/125.
- All “lost” paths. Add every path whose indicator is 1:
P(A) = 25/125 + 20/125 + 16/125 + 0 = 61/125
Quick check: 1 − 64/125 = 61/125, because the parcel is either lost somewhere or not lost at all.
- Divide. P(E3 | A) = (16/125) ÷ (61/125) = 16/61.
Answer: 16/61 (about 26.2%)
Common Mistakes to Avoid
- Swapping the condition. Using P(A | Ei) when the question wants P(Ei | A). Always ask: “What has already happened?”
- Forgetting the denominator. The circled path alone is only one route. You must divide by the total of all routes that give the evidence.
- Priors that do not add to 1. If they do not, a cause is missing (like “knows the answer” in Question 2).
- Ignoring the base rate. A very rare cause stays unlikely even with a good test (Question 5).
- Adding when you should multiply. Along a path we multiply. Only different paths are added.
- Overlapping causes. If two causes can happen together, Bayes’ theorem in this form cannot be applied directly.
Quick Revision
- Bayes’ theorem finds the probability of a cause given an observed effect.
- Causes must be mutually exclusive and exhaustive, with P(Ei) > 0 and P(A) > 0.
- Formula: P(Ei | A) = P(Ei) P(A | Ei) ÷ Σ P(Ej) P(A | Ej).
- The denominator is the law of total probability: P(A).
- On a tree: multiply along a path, add the paths that give the evidence, then divide the circled path by that total.
- Sanity check: all posterior probabilities must add up to 1.