On this concept: Formula

Not sure which lesson to do first? Find your level and get a plan →

Math · Statistics & Probability · Grade 9-12

Bayes' Theorem

Bayes' theorem computes the posterior probability of a hypothesis given evidence by combining the prior P(H), the likelihood P(E∣H), and the total evidence P(E): P(H∣E)=P(E∣H)P(H)P(E).

P(A∣B)=P(B∣A)⋅P(A)P(B)
Venn diagram of Event A and Event BA two-event view of bayes' theorem.ABA ∩ B
A: Event A
B: Event B
A two-event view of bayes' theorem.

Quick Answer

Bayes' theorem computes the posterior probability of a hypothesis given evidence by combining the prior P(H), the likelihood P(E∣H), and the total evidence P(E): P(H∣E)=P(E∣H)P(H)P(E). Use it when you know how likely the evidence is if a cause is true, and you need how likely the cause is now that you have seen the evidence: a positive medical test, a smoke alarm going off, a suspicious word in an email. The answer depends heavily on the prior; a rare cause can stay fairly unlikely even after strong evidence.

Why This 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?

Intuitive Explanation

Imagine 10,000 people, 1% of whom have a disease: 100 sick and 9,900 healthy. A test catches 90% of sick people, so 90 of the 100 test positive. It also wrongly flags 5% of healthy people, which is 495 of the 9,900. In total 585 people test positive, and only 90 of them are sick. So the chance that a person with a positive result is sick is 90585≈15%.

That count is Bayes' theorem in disguise. The numerator, 90, is P(+∣D)⋅P(D) scaled up to 10,000 people: the true positives. The denominator, 585, is P(+): every way a positive can happen, true or false. The prior P(D)=0.01 matters because it decides how large the healthy group is, and a small error rate applied to a huge group produces many false alarms.

Bayes is for flipping a conditional. If a table already gives the joint counts, such as 90 sick people among 585 positives, you can read P(D∣+) straight off as an ordinary conditional probability; nothing needs flipping. You need Bayes when you are handed the conditional in the other direction (how the test behaves given the disease) together with how common the disease is.

Think of it like this. 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.

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


When to Use

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.

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

How to Recognize It

Before using Bayes' theorem, sort what the problem gives you into how common each possible cause is and how likely the evidence is under each cause.

  1. Does the problem give a base rate, such as 1% of people having a disease or 3% of parts coming from a faulty machine?

    If yes, that is the prior, and it must enter the calculation; leaving it out is the classic base-rate error. If no base rate is given at all, the posterior cannot be found, however accurate the test is.

  2. Are you told how often the evidence appears both when the cause is present and when it is absent?

    If yes, build the denominator with the law of total probability: P(E)=P(E∣H)P(H)+P(E∣not H)P(not H). Without the false-positive rate, P(E) stays unknown.

  3. Is the evidence already summarized as counts in a two-way table?

    If yes, skip the formula: the right cell divided by its row or column total gives the conditional directly. Bayes' theorem is the same calculation done with rates instead of counts.

  4. Is the question asking for two events both happening, rather than one event given the other?

    If yes, use the multiplication rule, P(H and E)=P(H)P(E∣H), and stop there. Bayes divides that product by P(E) only when the question asks for the cause given the evidence.

Bayes' Theorem compared with Conditional probability, Compound probability, and Law of total probability

All four rows work with conditional chances, which is why they blur together. Ask what you need: a conditional you can read off directly (conditional probability), the reverse of the one you were given (Bayes), two events together (compound), or the overall chance of the evidence (total probability).

Bayes' Theorem

Meaning
Use this when you know a conditional in one direction plus a prior and need the reverse conditional (update a belief from evidence).
Key test
Am I given P(E∣H) and a prior, and asked for the flipped P(H∣E)?
Formula
P(A∣B)=P(B∣A)⋅P(A)P(B)
Example
A disease affects 1% of people. A test is 90% sensitive (P(+∣D)=0.9) and has a 5% false-positive rate (P(+∣no D)=0.05). Given a positive test, find P(D∣+).

Conditional probability

Meaning
Computes P(A∣B) directly from a known joint and marginal, without flipping or a prior.
Key test
Use when the needed direction is already the one you have.
Formula
P(A∣B)=P(A and B)P(B)
Example
P(soccer | 9th grade) from a table

Compound probability

Meaning
Combines events with and/or, not reversing a conditional.
Key test
Use when finding the chance of joint or either-of events.
Formula
P(A and B)=P(A)P(B∣A)
Example
Chance of a heart AND a face card

Law of total probability

Meaning
Builds the denominator P(E) by summing over all hypotheses; a piece Bayes relies on.
Key test
Use to compute the total evidence probability P(E).
Formula
P(E)=∑P(E∣Hi)P(Hi)
Example
Total chance of a positive test

Formula & Notation

P(A∣B)=P(B∣A)⋅P(A)P(B)
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.

How to read it: 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.

Worked Examples

Example 1 — Disease test

Easy

A disease affects 1% of people. A test is 90% sensitive (P(+∣D)=0.9) and has a 5% false-positive rate (P(+∣no D)=0.05). Given a positive test, find P(D∣+).
Show the steps and the answer
  1. Write the pieces: prior P(D)=0.01, P(+∣D)=0.9, P(+∣no D)=0.05.

    The question asks for P(D∣+), the reverse of the test accuracy we are given, so Bayes' theorem is needed.

  2. Total chance of a positive: P(+)=0.9(0.01)+0.05(0.99)=0.009+0.0495=0.0585.

    A positive can come from a sick person (true positive) or a healthy one (false positive), and both count.

  3. Apply Bayes: P(D∣+)=0.9⋅0.010.0585=0.0090.0585≈0.154.

    Of all the positives, only the true positives have the disease.

  4. Check with 10,000 people: 100 sick give 90 positives, 9,900 healthy give 495 positives, and 9090+495=90585≈0.154.

    Counting people gives the same answer and shows why: false positives outnumber true ones 5.5 to 1.

Answer: P(D∣+)≈0.154, about 15%

Takeaway: When a condition is rare, false positives from the large healthy group can outnumber true positives, so a positive result is weaker evidence than the test's accuracy suggests.

Example 2 — Reading off the test directly

Standard

A student sees the test is 'a test with 90% sensitivity and a 5% false-positive rate on a disease affecting 1%,' tests positive, and concludes there's a 90% chance they have the disease. Is that right?
Show the steps and the answer
  1. Name what the student used: 90% is P(+∣D), the chance that a sick person tests positive.

    The student wants P(D∣+), the chance that a person who tests positive is sick; the condition and the event are swapped.

  2. Count positives among 1,000 people: 10 sick give 9 positives, and 990 healthy give 0.05×990=49.5 positives on average.

    Natural frequencies show where positive results really come from.

  3. Find the share who are sick: 99+49.5=958.5≈0.154.

    This is Bayes' theorem done with counts; the 1% base rate pulls the answer far below 90%.

Answer: No — the real chance is about 15%, not 90%

Takeaway: P(+∣D) and P(D∣+) answer different questions; only the second tells a patient how worried to be, and it depends on the base rate.

Example 3 — Find the mistake: the wrong denominator

Application

Machine A makes 60% of a factory's parts and machine B makes 40%. A's parts are defective 2% of the time and B's 5% of the time. A part is found to be defective. Jordan writes: "P(B∣def)=0.05×0.400.05=0.40." Find the mistake and correct it.
Show the steps and the answer
  1. Check the numerator: P(def∣B) P(B)=0.05×0.40=0.020.

    This is the chance that a part is both from B and defective, so it is right.

  2. Spot the error: Jordan divided by 0.05, which is only B's defect rate.

    The denominator must be the chance that a part is defective at all, from either machine.

  3. Build P(def)=0.60×0.02+0.40×0.05=0.012+0.020=0.032.

    Every machine that can produce a defect contributes; this is the law of total probability.

  4. Divide: P(B∣def)=0.0200.032=0.625.

    B makes fewer parts but more than half the defects, because its defect rate is 2.5 times A's.

Answer: P(B∣def)=0.625

Takeaway: The denominator P(E) adds up the evidence from every hypothesis, here both machines; dividing by one hypothesis's likelihood leaves the others out.

Where You'll See It

  • Reading a cancer screening result

    Suppose 1% of women screened have breast cancer, the scan detects 90% of cancers, and 9% of healthy women get a false positive. Then P(cancer∣+)=0.0090.009+0.0891≈9%, which is why a positive screen leads to a follow-up test, not a diagnosis.

  • Spam filters sorting email

    If the word 'prize' appears in 20% of spam but only 1% of normal email, and half of all email is spam, then P(spam∣prize)=0.2(0.5)0.2(0.5)+0.01(0.5)=0.100.105≈0.95. Filters combine many words this way to score each message.

Common Mistakes

  1. The slip: Treating P(H∣E) as equal to P(E∣H)

    Instead: Bayes flips them, and the prior makes the two differ.

  2. The slip: Ignoring the base rate (prior)

    Instead: a rare condition keeps the posterior low even after strong evidence.

  3. The slip: Using the wrong denominator

    Instead: P(E) must total over ALL hypotheses (true and false), e.g. true positives plus false positives.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. P(A)=0.3, P(B∣A)=0.5 and P(B)=0.25. Find P(A∣B).

    Hint: Put the three numbers into Bayes' theorem.

  2. Box 1 has 3 red and 1 blue ball; Box 2 has 1 red and 3 blue. You flip a coin to choose a box and draw a red ball. What is P(Box 1∣red)?

    Hint: Find the chance of red through each box, then the share that came from Box 1.

  3. Machine A makes 60% of a factory's parts, 2% of them defective. Machine B makes 40%, 5% defective. A part is defective. What is the probability it came from Machine A?

    Hint: Find the total defect rate from both machines first.

  4. 2% of 1,000 people have a condition. A test catches 95% of people who have it and wrongly flags 10% of people who do not. Of those who test positive, what fraction have the condition?

    Hint: Count people: how many sick test positive, and how many healthy test positive?

  5. Of 200 students, 50 play chess, and 20 of those 50 also code. You want P(codes∣plays chess). Do you need Bayes' theorem?

    Hint: Can you read the answer straight from the counts?

  6. A spam filter flags 98% of spam and 2% of real emails; 10% of emails are spam. Ali says a flagged email is 98% likely to be spam. Correct Ali.

    Hint: 98% is the chance of a flag given spam. Find the total chance of a flag.

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Why does a positive result on a good test still leave the disease unlikely?

Picture 1,000 people. With a 1% base rate, 10 have the disease, and a test that catches 90% finds 9 of them. Of the 990 healthy people, 5%, about 50, also test positive. So about 59 people test positive and only 9 of them are sick: 959≈15%\frac{9}{59} \approx 15\%. The false positives from the huge healthy group swamp the true positives from the tiny sick group.

What happens if the person takes the test again and is positive a second time?

Use the first posterior as the new prior. If the two results are independent given the true condition, start from 0.154 instead of 0.01: 0.9×0.1540.9×0.154+0.05×0.846≈0.77\frac{0.9 \times 0.154}{0.9 \times 0.154 + 0.05 \times 0.846} \approx 0.77. Two positives make the disease much more likely. This chaining is the heart of Bayesian reasoning: each new piece of evidence updates the belief left by the one before.

Is Bayes' theorem used in spam filters?

Yes. A filter learns from past mail how often each word appears in spam and in normal mail, the likelihoods, and how much of all mail is spam, the prior. When a new email arrives, it combines the evidence from its words into a chance that the email is spam and moves it to the junk folder above some cutoff. These are called naive Bayes filters, because they treat the words as independent clues.

Who was Bayes?

Thomas Bayes was an English minister and mathematician who died in 1761. His essay on reasoning backwards from evidence to causes was found among his papers and published in 1763 by his friend Richard Price. Pierre-Simon Laplace later developed the same idea independently and much further. For much of the 20th century many statisticians distrusted the method because choosing a prior seemed subjective; today it is central to medicine and machine learning.

Learning Path

Bayes' Theorem

You are here

Next →

Nothing after this yet
You need Probability, Sample Space and especially Conditional Probability, including P(A and B)=P(B∣A)P(A), which Bayes rearranges. Bayes adds the step of reversing a conditional by bringing in a prior. With it you can analyse diagnostic tests and spam filters, and it is the starting point of Bayesian statistics, where a belief is updated each time new data arrive.

See Also