[Home](https://learningfolio.de5.net/) / [Math](https://learningfolio.de5.net/math/) / [Math glossary](https://learningfolio.de5.net/math/glossary/) / Bayes’ Theorem: Formula, Evidence, and Worked Examples

[Math glossary](https://learningfolio.de5.net/math/glossary/)

# Bayes’ Theorem: Formula, Evidence, and Worked Examples

Use Bayes’ theorem to calculate a posterior from a prior and evidence. Follow six examples on base rates, repeated tests and total probability.

Written by **Learningfolio Team**

We’re subject-matter experts in math, science, parent support, and education, with 100 years of combined experience. We believe in learning, experimenting, and growing, and we review one another’s work.

## On this page

* [TL;DR](https://learningfolio.de5.net/math/bayes-theorem/#tldr)
* [Key Points](https://learningfolio.de5.net/math/bayes-theorem/#key-points)
* [What is Bayes' theorem?](https://learningfolio.de5.net/math/bayes-theorem/#what-is-bayes-theorem)
* [Why does the formula work?](https://learningfolio.de5.net/math/bayes-theorem/#why-does-the-formula-work)
* [How do you find the denominator?](https://learningfolio.de5.net/math/bayes-theorem/#how-do-you-find-the-denominator)
* [Worked Bayes' Theorem Examples](https://learningfolio.de5.net/math/bayes-theorem/#worked-bayes-theorem-examples)
* [Mistakes That Change the Posterior](https://learningfolio.de5.net/math/bayes-theorem/#mistakes-that-change-the-posterior)
* [Try It Yourself](https://learningfolio.de5.net/math/bayes-theorem/#try-it-yourself)
* [Questions About Bayes' Theorem](https://learningfolio.de5.net/math/bayes-theorem/#questions-about-bayes-theorem)
* [Conclusion](https://learningfolio.de5.net/math/bayes-theorem/#conclusion)
* [Read More](https://learningfolio.de5.net/math/bayes-theorem/#read-more)
* [Research Behind This Article](https://learningfolio.de5.net/math/bayes-theorem/#research-behind-this-article)

## TL;DR

**Bayes' theorem updates the probability of a hypothesis after evidence arrives.** Multiply the prior by the likelihood, then divide by the overall probability of the evidence.

## Key Points

* The prior is the starting probability before considering the evidence.
* The likelihood asks how often the evidence occurs when the hypothesis holds.
* The posterior asks how likely the hypothesis is after observing that evidence.
* The denominator includes every way the same evidence can occur.
* Conditional probabilities depend on which event appears after the bar.

## What is Bayes' theorem?

Let $H$ be a hypothesis or event, and let $E$ be the evidence. When $P(E)>0$ and the indicated conditional probabilities are defined, use

$$
P(H\mid E)=\frac{P(E\mid H)P(H)}{P(E)}.
$$

| Part | Name | Question |
| --- | --- | --- |
| $P(H)$ | Prior | How likely was $H$ before observing $E$? |
| $P(E\mid H)$ | Likelihood | If $H$ holds, how likely is the evidence? |
| $P(E)$ | Overall evidence probability | How likely is the evidence across the full population? |
| $P(H\mid E)$ | Posterior | After the evidence, how likely is $H$? |

The direction matters. If a machine flags 80% of defective parts, that number is $P(\mathrm{flag}\mid\mathrm{defect})$. The probability that a flagged part is defective answers the reverse question.

## Why does the formula work?

If $P(H)>0$ and $P(E)>0$, write the probability of both events in two ways:

$$
P(H\cap E)=P(H\mid E)P(E)=P(E\mid H)P(H).
$$

Divide by $P(E)$ to get Bayes' formula. MIT OpenCourseWare and the OpenStax probability text derive it from conditional probability. If an event has probability zero, a conditional probability given that event is undefined in the elementary ratio formula.

## How do you find the denominator?

Split the sample space into disjoint cases covering all possibilities. If you split into $H$ and its complement $H^c$, the law of total probability gives

$$
P(E)=P(E\mid H)P(H)+P(E\mid H^c)P(H^c).
$$

With a larger partition $H_1,\ldots,H_m$ the denominator is $\sum_iP(E\mid H_i)P(H_i)$, summed over the cases with positive prior probability. Draw a tree, multiply along each path to the same evidence, and add across those paths. The [De Morgan's laws guide](https://learningfolio.de5.net/math/de-morgans-law/) reviews the complement notation.

![In 200 parts, 8 defective parts and 19 nondefective parts are flagged, so the defective share of flagged parts is 8 out of 27](https://learningfolio.de5.net/assets/versioned/bayes-theorem-inspection-counts.4464aeca17e7.webp)


Among the flagged parts, the reference group has 27 parts. Eight are defective.

Expected counts often make the calculation easier. Start with a convenient total and apply the prior fractions. Split each group by the evidence rate. Divide the target group within the evidence by the count of all items showing the evidence. The [statistics practice guide](https://learningfolio.de5.net/math/statistics-questions/) shows why the subgroup denominator matters.

## Worked Bayes' Theorem Examples

### Example 1

Five percent of parts are defective. A tester flags 80% of defective parts and 10% of good parts. What proportion of flagged parts are defective under this model?

1. In a group of 200, the model gives 10 defective and 190 good parts.
2. It flags $0.8(10)=8$ defective parts and $0.1(190)=19$ good parts.
3. Of $8+19=27$ flagged parts, 8 are defective. The probability is $8/27\approx29.63\%$.

### Example 2

Line A makes 60% of parts and has a 2% defect rate. Line B makes 40% and has a 5% defect rate. A randomly selected part is defective. What is the probability it came from line B?

1. Line B contributes $0.4(0.05)=0.020$ to the overall defect probability.
2. Line A contributes $0.6(0.02)=0.012$, so the total is $0.032$.
3. Divide to get $0.020/0.032=5/8=62.5\%$.

### Example 3

In Example 1, what is the probability that a part is defective if it was not flagged?

1. Of 10 defective parts, $10-8=2$ are not flagged.
2. Of 190 good parts, $190-19=171$ are not flagged.
3. There are 173 unflagged parts and 2 defects among them. The probability is $2/173\approx1.16\%$.

### Example 4

Use the same tester for two readings. Assume the readings are independent given a part's defect status. What is the probability of a defect after two flags?

1. For defective parts, the chance of two flags is $0.8^2$. For good parts, it is $0.1^2$.
2. The two joint contributions are $0.05(0.8)^2=0.032$ and $0.95(0.1)^2=0.0095$.
3. The posterior is $0.032/(0.032+0.0095)=64/83\approx77.11\%$. If the same error influences both readings, the independence assumption needs reconsideration.

### Example 5

Choose one of three boxes with equal probability. They contain respectively 2, 5 and 8 green tiles out of 10. A tile drawn from the chosen box is green. What is the probability you chose the third box?

1. The joint probability of the third box and a green tile is $(1/3)(8/10)=8/30$.
2. Across the boxes, the probability of green is $(2+5+8)/30=15/30$.
3. The posterior is $(8/30)/(15/30)=8/15$, approximately 53.33%.

### Example 6

The same tester's defect prior changes from 5% to 1%, with the two flag rates unchanged. What is the new defective share of flags?

1. The defect-and-flag probability is $0.01(0.8)=0.008$.
2. The good-and-flag probability is $0.99(0.1)=0.099$.
3. The defective share is $0.008/0.107=8/107\approx7.48\%$. The same likelihoods yield a different posterior because the prior changed.

## Mistakes That Change the Posterior

### Mistake 1: Switching the two events around the conditional bar

The event after the bar sets the group being considered. Make sure the result answers the requested direction, such as defect given flag.

### Mistake 2: Counting only one path in the denominator

The evidence can occur even when the hypothesis fails. Add all disjoint paths to the same evidence, including false alarms in the tester example.

### Mistake 3: Multiplying likelihoods without an independence assumption

For repeated evidence, use the joint likelihood or conditional probabilities that reflect the relationship between observations. The product of two identical likelihoods applies only when the readings are conditionally independent and have those likelihoods.

## Try It Yourself

1. Forty percent of items come from line B. Both lines have the same positive probability of producing the observed sticker. What is $P(B\mid\mathrm{sticker})$?
2. A prior is $1/4$, the likelihood is $2/3$, and the overall evidence probability is $1/2$. Find the posterior.
3. What is $P(H\mid E)$ in the ratio formula if $P(E)=0$?

### Answers and Reasoning

1. Multiply both lines' priors by the same likelihood. The common term cancels, so the posterior remains 40%.
2. Use $(1/4)(2/3)/(1/2)=1/3$.
3. The ratio is undefined because its denominator is zero.

## Questions About Bayes' Theorem

### Can the evidence lower the probability of a hypothesis?

Yes. If $P(E\mid H)$ is smaller than $P(E)$, the update multiplies the prior by a factor below 1. Evidence less common when $H$ holds reduces its probability.

### Can today's posterior become tomorrow's prior?

Yes, when updating for additional evidence. The next likelihood must condition on what was already observed when that information affects the new evidence. The Stanford Encyclopedia explains this sequential interpretation and its assumptions.

## Conclusion

* Identify the hypothesis, evidence, and direction of conditioning.
* Multiply the hypothesis prior by its evidence likelihood and add all evidence paths for the denominator.
* Check that the final probability belongs to the evidence group you actually observed.

## Read More

* [Build a sample space with playing cards](https://learningfolio.de5.net/math/probability-and-playing-cards/)
* [Distinguish a population parameter from a sample statistic](https://learningfolio.de5.net/math/parameters-and-statistics/)

## Research Behind This Article

1. MIT OpenCourseWare, *Introduction to Statistical Methods in Economics — Lecture 4*. [MIT](https://ocw.mit.edu/courses/14-30-introduction-to-statistical-methods-in-economics-spring-2009/e126cf189fd96b8cadf7e28d578e12cf_MIT14_30s09_lec04.pdf)
2. OpenStax, *Principles of Data Science — Probability Theory*. [OpenStax](https://openstax.org/books/principles-data-science/pages/3-4-probability-theory)
3. Stanford Encyclopedia of Philosophy, *Bayes' Theorem*. [Stanford](https://plato.stanford.edu/entries/bayes-theorem/)
4. University of Toronto, Mike Evans and Jeffrey Rosenthal, *Probability and Statistics: The Science of Uncertainty*. [University of Toronto](https://utstat.toronto.edu/mikevans/oldjeffrosenthal/book.pdf)
