Conditional Probability and Bayes

Bayes Theorem Explained with Everyday Examples

Derive Bayes theorem from conditional probability and see it work on a frequency tree with an everyday spam-filter example, step by step and with checked numbers.

On this page
  1. The question Bayes theorem answers
  2. Starting from conditional probability
  3. A worked example with a frequency tree
  4. Why the prior cannot be skipped
  5. Updating more than once
  6. Where it shows up in games
  7. A quick recipe

The question Bayes theorem answers

Many everyday questions have the same shape. You start with a rough idea of how likely something is, then you see a clue, and you want to know how likely the thing is now. Is this email spam, given that it contains a certain word? Is a die loaded, given the rolls so far? Is an opponent holding a strong hand, given how they just played?

Bayes theorem is the rule for making that update. It does not add new information of its own. It only keeps the arithmetic honest, so the starting chance and the strength of the clue are both counted properly.

Starting from conditional probability

The idea of conditional probability is the foundation. Write P(A | B) for “the chance of A, given that B has happened”. Restricting attention to the cases where B happened gives:

P(A | B) = P(A and B) / P(B)

Read it as a fraction of a fraction: out of all the situations where B occurs, what share also have A?

The same logic works the other way round, so P(B | A) = P(A and B) / P(A). Rearranging that gives P(A and B) = P(B | A) × P(A). Substitute this into the first line and you have the result:

P(A | B) = P(B | A) × P(A) / P(B)

That single line is Bayes theorem. The pieces have names:

  • P(A) is the prior: how likely A was before the clue.
  • P(B | A) is the likelihood: how often the clue appears when A is true.
  • P(B) is the overall chance of seeing the clue at all, whether or not A is true.
  • P(A | B) is the posterior: the updated chance after the clue.

The denominator P(B) is usually found by adding up every way the clue can arise, which is the job of the law of total probability.

A worked example with a frequency tree

The formula is easy to misuse when it is stated in percentages, so start with counts. The numbers below are invented purely for illustration.

Suppose 20% of the emails arriving in an inbox are spam. A particular word, say “prize”, appears in 50% of spam emails and in 5% of non-spam emails. An email arrives containing “prize”. How likely is it to be spam?

Imagine 1,000 emails and split them in a tree:

Branch Emails Contains “prize”
Spam (20%) 200 50% of 200 = 100
Not spam (80%) 800 5% of 800 = 40

Now look only at emails containing the word. There are 100 + 40 = 140 of them, and 100 of those are spam. So the chance of spam is 100 / 140 = 5/7, about 71%.

Check it against the formula. P(spam) = 0.20, P(word | spam) = 0.50, and P(word) = 0.20 × 0.50 + 0.80 × 0.05 = 0.10 + 0.04 = 0.14. Then 0.50 × 0.20 / 0.14 = 0.10 / 0.14 = 5/7. The tree and the formula agree, as they must.

Notice what happened. The word is ten times more common in spam than in ordinary mail (50% against 5%), yet the answer is about 71%, not 90% or 95%. The prior matters: spam was only one email in five to begin with.

Why the prior cannot be skipped

It is tempting to answer “the word shows up in 50% of spam, so this is 50% likely to be spam”, or to focus on the 5% rate for ordinary mail. Both mix up P(B | A) with P(A | B). They answer different questions, and the gap between them is exactly what the prior and the denominator fix.

The effect is strongest when the thing you are looking for is rare. Suppose spam were only 1% of the mail, with the same word habits. In 1,000 emails, 10 are spam and 5 contain the word, while 990 are not spam and about 49.5 contain it (5% of 990). The chance of spam given the word falls to roughly 5 / 54.5, about 9%. The clue is just as strong, but the starting point is much lower. This trap is explored on its own in the article on base rate neglect, and the same arithmetic drives the surprising results behind false positives in screening tests.

Updating more than once

Bayes theorem can be applied repeatedly. The posterior from one clue becomes the prior for the next, as long as the clues are reasonably independent of each other given the hypothesis. In the spam example, after seeing “prize” the chance of spam moves from 20% to about 71%. A second independent clue would start from 71%, not 20%.

This is why the method suits situations that unfold over time, such as watching a series of coin tosses and gradually revising a belief about whether the coin is fair. It also shows where care is needed: if two clues are really the same information in disguise, counting both overstates the evidence.

Where it shows up in games

Bayes theorem is a way of reasoning, not a strategy for beating anything. In card games the cards you can see change what is possible for the cards you cannot. In dice and loot-style games, a run of unusual results might make you wonder whether the stated rates are right. In both cases the structure is the same: a prior, a clue, and an updated chance.

It is worth being clear about limits. Casino games carry a house edge, each spin or shuffle is independent of the last, and past results do not change future odds. Bayesian reasoning cannot turn a negative-expectation game into a profitable one. Gambling can be harmful, and anyone who feels it is becoming a problem should contact a local support service.

A quick recipe

  1. Write down the prior: how common is the thing, before any clue?
  2. Imagine a round number of cases, such as 1,000 or 10,000.
  3. Split them by the prior, then split each group by how often the clue appears.
  4. Keep only the cases that show the clue.
  5. The answer is the share of those cases that have the thing you care about.

If you can do these five steps with counts, you can do Bayes theorem. The formula is just the same bookkeeping written in symbols. When the numbers are awkward, a tree makes each step visible, and checking that the final counts add up is a reliable way to catch a slip.

Keep exploring

Guides from other topics

All topics →