Conditional Probability and Bayes

The Law of Total Probability

Learn how the law of total probability combines cases into one overall chance, and why it is the denominator in Bayes theorem, with a checked illustrative example.

On this page
  1. The idea in one sentence
  2. The formula and what it means
  3. A worked example with three chests
  4. Why it is the denominator of Bayes theorem
  5. Where partitions come from
  6. Common errors
  7. A short caution about games

The idea in one sentence

If the world can be split into a few separate, exhaustive cases, the overall chance of an event is the weighted average of its chance in each case, where the weights are how likely each case is.

That is the law of total probability. It formalises something people do informally all the time: “it depends which one I get, so let me work out each possibility and combine them.”

The formula and what it means

Suppose the cases are B1, B2, …, Bn. They must satisfy two conditions: they do not overlap (at most one is true), and together they cover every possibility (exactly one is true). Such a set is called a partition. Then for any event A:

P(A) = P(A | B1) × P(B1) + P(A | B2) × P(B2) + … + P(A | Bn) × P(Bn)

Each term answers “what is the chance that this case happens and A happens too?” Adding the terms collects every route to A. If the cases did not cover everything, some routes would be missing; if they overlapped, some routes would be counted twice. Both failures give wrong answers.

The formula relies on conditional probability: each P(A | Bi) is the chance of A inside one case. It is also what you read off the endpoints of a probability tree by adding the paths that end in A.

A worked example with three chests

This is an invented game mechanic, used only to illustrate the arithmetic. A player opens one chest at random out of three types:

  • Chest A is opened 50% of the time, and gives a rare item 10% of the time.
  • Chest B is opened 30% of the time, and gives a rare item 20% of the time.
  • Chest C is opened 20% of the time, and gives a rare item 5% of the time.

The chest types cover all cases (50% + 30% + 20% = 100%) and exactly one is opened, so they form a valid partition. What is the overall chance of a rare item on a single opening?

  • Via A: 0.50 × 0.10 = 0.05
  • Via B: 0.30 × 0.20 = 0.06
  • Via C: 0.20 × 0.05 = 0.01

Total: 0.05 + 0.06 + 0.01 = 0.12, so a 12% chance.

Notice that 12% is not the plain average of 10%, 20% and 5%, which would be about 11.7%. It is a weighted average, and chest A, being the most often opened, pulls the result toward 10% while B, which has the highest rare rate, pulls it up. Weights matter.

To sanity-check, imagine 1,000 openings: 500 of chest A (50 rare), 300 of chest B (60 rare), 200 of chest C (10 rare). Total rares: 50 + 60 + 10 = 120, or 12%. This counting version is the approach used in natural frequencies.

Why it is the denominator of Bayes theorem

Bayes theorem reverses a conditional probability:

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

The bottom of the fraction, P(A), is the overall chance of the evidence. When the possible causes form a partition, the law of total probability gives it directly. So the law supplies the denominator, and Bayes theorem uses it.

Continue the chest example. You see a rare item. Which chest was it likely to have come from? The top of each fraction is the same product you calculated above; the bottom is 0.12.

  • Chest A: 0.05 / 0.12 = 5/12, about 41.7%
  • Chest B: 0.06 / 0.12 = 1/2, or 50%
  • Chest C: 0.01 / 0.12 = 1/12, about 8.3%

Check that they add to 1: 5/12 + 6/12 + 1/12 = 12/12. Yes. This is a good sign, because the posterior chances across a partition must always sum to 1, and because dividing every term by the same total is what guarantees it.

Chest B was only opened 30% of the time, yet it is the most likely source of a rare item, because it produces rares most generously. Chest C, which seldom gives a rare, is rarely the source. The prior and the rate both matter.

Where partitions come from

The art of using the law is picking good cases. Some familiar choices:

  • Which die, bag or deck am I using? Each source is a case.
  • Is the thing true or false? Two cases cover everything, as in a test for a condition: those who have it, and those who do not. This split is what produces false positives alongside true ones.
  • Which category of player or opponent? In reading hidden information, the cases are the possible holdings.
  • First step outcome. In multi-step events, condition on what happened first. Drop-table style mechanics often work this way, with a choice of table followed by a roll on that table, similar to weighted random tables.

When a problem feels too tangled to solve at once, ask “what single thing would make it easy if I knew it?” Make that the partition, solve within each case, and combine.

Common errors

  • Weights that do not sum to 1. If the case chances do not total 100%, a case is missing or something is wrong.
  • Overlapping cases. If a single outcome belongs to two cases, it will be counted twice.
  • Using the wrong conditional. The terms must be P(A | Bi), the chance of the event within the case, not P(Bi | A).
  • Treating an average of rates as the answer. The weights are essential.

A short caution about games

This is a calculation tool, not a way to find an advantage. If a game has a house edge, combining its cases gives you the overall expected outcome, which is still unfavourable over the long run. Each play is independent, and an unlikely sequence can happen at any time. Gambling carries real risk, so if it stops being enjoyable or starts to cause stress, contact a local support service.

The complete guide to conditional probability and bayes

Bayes Theorem Explained with Everyday Examples
Read the guide

Keep exploring

Guides from other topics

All topics →