James Ashton MathsFREE MATHEMATICS. OPEN TO EVERYONE.
HomeIB DiplomaA levelAbout

Bayes’ theorem

How to reverse a conditional probability: from the chance of a positive test given the disease to the chance of the disease given a positive test. Bayes’ theorem with two and with three events.

AHL 4.13HL onlyPaper 1Paper 2≈ 60 min to work through
Before you start: conditional probability, tree diagrams and the formula P(A∣B)=P(A∩B)P(B). See Probability.

1What you need to know

Tick these off as you go. By the end of the page you should be able to do all of them without notes.

  • Explain why P(A∣B) and P(B∣A) are usually differentAHL 4.13
  • Find P(B) by adding the branches of a tree (the law of total probability)AHL 4.13
  • Use Bayes’ theorem for an event A and its complement A′AHL 4.13
  • Use Bayes’ theorem with three mutually exclusive, exhaustive eventsAHL 4.13
  • Interpret a result in context, including false positives and repeated testsAHL 4.13

2Notes & worked examples

Each idea is followed by a worked example. Try the question yourself first, then reveal the solution one step at a time.

The big idea

A tree diagram is drawn in the order things happen: first whether a person has a disease, then whether their test is positive. So the tree gives you P(positive∣disease) directly. The question people actually care about runs the other way: given a positive test, how likely is the disease? Bayes’ theorem turns the tree around. It is nothing more than the definition of conditional probability, used carefully.

2.1 Two conditionals are not the same

Suppose 1% of a population has a disease. A test detects it 95% of the time, and gives a positive result for 5% of healthy people (a false positive). Most people guess that a positive test means about a 95% chance of having the disease. The true answer is about 16%.

The quickest way to see why is to imagine 10 000 people. 100 have the disease and 95 of them test positive. 9900 are healthy and 5% of them, 495 people, also test positive. So 590 people test positive, and only 95 of them are ill:

P(disease∣positive)=9595+495=95590≈0.161

The false positives swamp the true positives because healthy people vastly outnumber ill people. P(+∣D)=0.95, but P(D∣+)≈0.161. Mixing up these two is a famous error in medicine and in court cases.

2.2 Bayes’ theorem for an event and its complement

Start from P(A∣B)=P(A∩B)P(B). The numerator is one branch of the tree: P(A∩B)=P(A)P(B∣A). The denominator is the sum of every branch that ends in B: P(B)=P(A)P(B∣A)+P(A′)P(B∣A′).

Bayes’ theorem In formula booklet
P(A∣B)=P(A)P(B∣A)P(A)P(B∣A)+P(A′)P(B∣A′)

The numerator is the branch you want. The denominator is all the branches that end in B.

Worked example 1Paper 1
Events A and B satisfy P(A)=0.3, P(B∣A)=0.6 and P(B∣A′)=0.2. Find P(A∣B).
P(A)P(B∣A)=0.3×0.6=0.18
The branch "A then B".
P(A′)P(B∣A′)=0.7×0.2=0.14
P(B)=0.18+0.14=0.32
Law of total probability: add every branch ending in B.
P(A∣B)=0.180.32=916
Worked example 2Paper 2
1% of a population has a disease D. A test gives a positive result for 95% of people with D and for 5% of people without D. Find the probability that a person who tests positive has D.
Tree: P(D)=0.01, P(+∣D)=0.95; P(D′)=0.99, P(+∣D′)=0.05
Draw the tree first, in the order things happen.
P(+)=0.01×0.95+0.99×0.05=0.0095+0.0495=0.059
P(D∣+)=0.00950.059=0.161 (3 s.f.)
The same 0.161 as the 10 000-people argument.
Why does counting people work?

Both methods are the same calculation. Counting people (95 out of 590) is the formula with every probability multiplied by 10 000. If you are unsure which numbers go where in the formula, count imaginary people: it is hard to get it wrong.

2.3 Three (or more) events

The IB course also covers three events A1,A2,A3 that are mutually exclusive and exhaustive (exactly one of them happens). Typical examples: three machines in a factory, three ways of getting to school, three bags to choose from.

Bayes’ theorem with three events In formula booklet
P(Ai∣B)=P(Ai)P(B∣Ai)P(A1)P(B∣A1)+P(A2)P(B∣A2)+P(A3)P(B∣A3)
Worked example 3Paper 2
A factory has three machines. Machine A makes 50% of the items, B makes 30% and C makes 20%. The proportions of defective items are 2% for A, 3% for B and 5% for C. An item is chosen at random.
(a) Find the probability that it is defective.
(b) Given that it is defective, find the probability that it was made by C.
(a) P(def)=0.5(0.02)+0.3(0.03)+0.2(0.05)
One branch for each machine.
=0.010+0.009+0.010=0.029
(b) P(C∣def)=0.2×0.050.029=0.0100.029=0.345 (3 s.f.)
Machine C makes only 20% of items but 34.5% of the defective ones.
Comment in context: C is the least reliable machine.
Worked example 4 (faded)Paper 2
In WE3, find the probability that a defective item was made by machine A.
P(A∣def)=0.0100.029= 0.345 (3 s.f.). The three answers P(A∣def),P(B∣def),P(C∣def) must add to 1.  ← you work this out

2.4 Updating: testing twice

Bayes’ theorem updates a probability when new evidence arrives. The probability before the evidence is the prior; the probability after is the posterior. After one positive test the probability of disease rose from 0.01 to 0.161. If the person is tested again (independently), the 0.161 becomes the new prior.

Worked example 5Paper 2
In WE2, a person tests positive and then takes the test a second time, independently of the first. Find the probability that they have D given that both tests are positive.
Prior is now P(D)=0.16102, P(D′)=0.83898
Keep full accuracy from the previous answer.
P(D∣++)=0.16102×0.950.16102×0.95+0.83898×0.05=0.152970.19492
=0.785 (3 s.f.)
Check from scratch: 0.01×0.9520.01×0.952+0.99×0.052=0.0090250.0115=0.785.
A checklist for any Bayes question
  1. Identify the events and write down every probability you are given, using ∣ notation.
  2. Draw the tree in the order things happen (the "cause" first, the "evidence" second).
  3. Find the probability of the evidence by adding every branch that ends in it.
  4. Divide the branch you want by that total.
  5. Check: is the answer sensible? Do the posteriors add to 1?
On your TI-Nspire Calculator tricks →

Bayes questions are short arithmetic, but long decimals are common. Store intermediate results: type 0.01*0.95+0.99*0.05, then press ctrl var and store it as pb. Then 0.0095/pb gives P(D∣+) with no rounding error.

3Explore it

Each square is one person out of 1000. Change how common the disease is and how good the test is, and watch what fraction of the positive results are true positives.

4Common mistakes & exam tips

Common mistakes

  • Confusing P(A∣B) with P(B∣A). Write the probability you want in ∣ notation before starting.
  • Using only one branch for P(B) in the denominator. It must include every branch that ends in B.
  • Forgetting the complement: P(B∣A′) is not 1−P(B∣A).
  • Rounding the denominator early and losing accuracy in a Paper 2 answer.
  • In a repeated test, using 0.01 again as the prior instead of the updated probability.

Exam tips

  • Always draw the tree. Examiners give method marks for the correct branches even if the arithmetic goes wrong.
  • Questions often say "given that the item is defective" or "given that the student was late": that event is the one in the denominator.
  • In a three-event question, check that your three posterior probabilities add to 1.
  • Give a one-line interpretation in context when asked, e.g. "most positive results are false positives".

5Practice

Fluency questions build the basics. Problem-solving questions make you think about which method to use.

FluencyP1
Given P(A)=0.4, P(B∣A)=0.5 and P(B∣A′)=0.25, find P(A∣B).
P(B)=0.2+0.15=0.35, so P(A∣B)=0.20.35=47.
FluencyP2
It rains on 30% of days. On a rainy day the bus is late with probability 0.4; on a dry day, 0.1. Given that the bus is late, find the probability that it rained.
0.120.12+0.07=1219≈0.632
FluencyP3
Factory A makes 60% of a product and 1% of its items are faulty. Factory B makes the rest and 4% of its items are faulty. Given that an item is faulty, find the probability that it came from A.
0.0060.006+0.016=311≈0.273
FluencyP4
A bag holds two fair coins and one coin with two heads. A coin is chosen at random and tossed, and shows a head. Find the probability that it is the two-headed coin.
1/31/3+23·12=12
Problem solvingP5
A die is rolled. If it shows a 6, a ball is taken from bag 1 (4 red, 6 green); otherwise from bag 2 (7 red, 3 green). The ball is red. Find the probability that it came from bag 1.
16(0.4)16(0.4)+56(0.7)=0.43.9=439≈0.103
Problem solvingP6
A test has P(+∣D)=0.9 and P(+∣D′)=0.1. Find the prevalence P(D) for which P(D∣+)=0.5.
0.9p=0.1(1−p)⇒p=0.1

6Exam-style questions

Original questions in the style of the IB exam, with full markschemes. Give yourself about 1 minute per mark.

Question 1Paper 1[6 marks]

Box A contains 3 red and 2 blue counters. Box B contains 1 red and 4 blue counters. A fair coin is tossed: if it shows heads a counter is taken from box A, otherwise from box B.

  • (a)Find the probability that the counter is red.[3]
  • (b)Given that the counter is red, find the probability that it was taken from box A.[3]
(a)
tree diagram or 12×35+12×15M1A1
25A1
(b)
12×3525M1A1
34A1
Question 2Paper 2[7 marks]

At a school, 40% of students travel by bus, 35% by car and the rest walk. The probability of being late is 0.1 for a bus traveller, 0.05 for a car traveller and 0.02 for a walker. A student is chosen at random.

  • (a)Find the probability that the student is late.[3]
  • (b)Given that the student is late, find the probability that they travelled by bus.[2]
  • (c)Given that the student is not late, find the probability that they travelled by car.[2]
(a)
0.4(0.1)+0.35(0.05)+0.25(0.02)M1A1
0.0625A1
(b)
0.040.0625M1
0.64A1
(c)
0.35×0.951−0.0625M1
0.355A1
Question 3Paper 2[7 marks]

A disease affects 1% of a population. A test gives a positive result for 95% of people with the disease and for 5% of people without it.

  • (a)A person tests positive. Find the probability that they have the disease.[3]
  • (b)The person takes the test again, independently, and again tests positive. Find the probability that they have the disease.[3]
  • (c)Comment on your answers.[1]
(a)
P(+)=0.01(0.95)+0.99(0.05)=0.059M1A1
0.00950.059=0.161A1
(b)
using 0.161 as the new prior, or 0.01×0.952 over 0.01×0.952+0.99×0.052M1A1
0.785A1
(c)
one positive test is weak evidence because false positives outnumber true positives; a second positive makes the disease likelyR1

7Check yourself

Six quick questions, marked instantly. Aim for 6/6 before moving on. Fractions like 3/2 are accepted.

8Past-paper practice

Once you're scoring well above, try real IB questions. Your school or teacher will have these papers.

PaperQuestionFocusDifficulty
Nov 2025 · TZ1 · Paper 2Q7Two machines with different defect rates; a conditional probability given the number of defects★★
May 2025 · TZ3 · Paper 2Q11Which person entered a survey, given that it was entered inaccurately★★★
Spotted a mistake on this page?Tell me and I'll fix it. The button opens an email with this page already named, or write to jamesashtonmaths@gmail.com.
Report a mistake