Skip to content
VibeFormer
Beginner20 min

The Law of Total Probability

Partitioning a sample space to compute awkward probabilities, with tree diagrams.

The Law of Total Probability

Intuition first

Sometimes a probability is awkward to compute directly but easy to compute once you know which situation you are in.

"What is the chance a randomly chosen visitor buys something?" is hard to answer in one step. But split visitors into mobile and desktop, and each piece becomes easy: mobile visitors buy 20% of the time, desktop visitors 40% of the time. If 60% of traffic is mobile, the overall rate is the weighted average

0.20×0.60  +  0.40×0.40  =  0.280.20 \times 0.60 \;+\; 0.40 \times 0.40 \;=\; 0.28

That is the whole law. Break the world into non-overlapping cases, solve each, then recombine weighted by how likely each case is.

The only thing that ever goes wrong is the splitting: the cases must not overlap, and together they must cover everything.

Partitions

A collection of events B1,B2,,BnB_1, B_2, \dots, B_n is a partition of the sample space when two conditions hold:

BiBj=for all ij(no overlap)B_i \cap B_j = \varnothing \quad \text{for all } i \neq j \qquad \text{(no overlap)} B1B2Bn=Ω(covers everything)B_1 \cup B_2 \cup \dots \cup B_n = \Omega \qquad \text{(covers everything)}

Exactly one of the BiB_i occurs, always. The simplest partition is any event and its complement: {B,Bc}\{B, B^c\}.

Notation used in this lesson
SymbolMeaning
B₁ … BₙA partition — mutually exclusive and exhaustive events
P(Bᵢ)Prior weight of case i — how likely that case is
P(A | Bᵢ)Probability of A within case i
ΣSum over all cases
B₁B₂B₃B₄AΩ
A partition splits Ω into non-overlapping regions that cover it entirely. The event A (shaded) is carved into one slice per region, and those slices are disjoint.

The law

For any event AA and any partition B1,,BnB_1, \dots, B_n with P(Bi)>0\Prob(B_i) > 0:

P(A)=i=1nP(ABi)P(Bi)\Prob(A) = \sum_{i=1}^{n} \Prob(A \mid B_i)\,\Prob(B_i)

The two-case version, used constantly:

P(A)=P(AB)P(B)+P(ABc)P(Bc)\Prob(A) = \Prob(A \mid B)\Prob(B) + \Prob(A \mid B^c)\Prob(B^c)
Derivation from the axiomsAdvanced

Because the BiB_i partition Ω\Omega, the event AA can be written as AA intersected with the whole space, then distributed:

A=AΩ=A(B1B2Bn)A = A \cap \Omega = A \cap (B_1 \cup B_2 \cup \dots \cup B_n)=(AB1)(AB2)(ABn)= (A \cap B_1) \cup (A \cap B_2) \cup \dots \cup (A \cap B_n)

These pieces are pairwise disjoint. If iji \neq j then

(ABi)(ABj)=A(BiBj)=A=(A \cap B_i) \cap (A \cap B_j) = A \cap (B_i \cap B_j) = A \cap \varnothing = \varnothing

so Axiom 3 (additivity) applies:

P(A)=i=1nP(ABi)\Prob(A) = \sum_{i=1}^{n} \Prob(A \cap B_i)

Finally rewrite each joint using the multiplication rule, P(ABi)=P(ABi)P(Bi)\Prob(A \cap B_i) = \Prob(A \mid B_i)\Prob(B_i):

P(A)=i=1nP(ABi)P(Bi)\Prob(A) = \sum_{i=1}^{n} \Prob(A \mid B_i)\,\Prob(B_i)

Two ingredients only: disjointness lets you add, and the multiplication rule converts joints into conditionals.

A useful sanity check

Because the weights P(Bi)\Prob(B_i) sum to 1, the result is a genuine weighted average. It must therefore lie between the smallest and largest of the conditional probabilities:

miniP(ABi)    P(A)    maxiP(ABi)\min_i \Prob(A \mid B_i) \;\leq\; \Prob(A) \;\leq\; \max_i \Prob(A \mid B_i)

In the shop example, 0.280.28 sits between 0.200.20 and 0.400.40. If your answer falls outside that range, the arithmetic is wrong — this catches errors instantly.

Solved problem 1 · Three factories

A company sources components from three factories. Factory A supplies 50% of components with a 2% defect rate; factory B supplies 30% with a 3% defect rate; factory C supplies 20% with a 5% defect rate. A component is picked at random. What is the probability it is defective?

Step 1 — identify the partition and check it

The factories partition the components: a component comes from exactly one factory, and the three cover all supply.

P(A)=0.50,P(B)=0.30,P(C)=0.20\Prob(A) = 0.50, \qquad \Prob(B) = 0.30, \qquad \Prob(C) = 0.20

Check exhaustiveness: 0.50+0.30+0.20=1.00  0.50 + 0.30 + 0.20 = 1.00 \;\checkmark

Step 2 — write the conditional defect rates

Let DD = "the component is defective".

P(DA)=0.02,P(DB)=0.03,P(DC)=0.05\Prob(D \mid A) = 0.02, \qquad \Prob(D \mid B) = 0.03, \qquad \Prob(D \mid C) = 0.05

Step 3 — apply the law term by term

P(D)=P(DA)P(A)+P(DB)P(B)+P(DC)P(C)\Prob(D) = \Prob(D \mid A)\Prob(A) + \Prob(D \mid B)\Prob(B) + \Prob(D \mid C)\Prob(C)=0.02(0.50)+0.03(0.30)+0.05(0.20)= 0.02(0.50) + 0.03(0.30) + 0.05(0.20)=0.010+0.009+0.010= 0.010 + 0.009 + 0.010=0.029= 0.029

Step 4 — sanity check

The conditional rates range from 0.02 to 0.05, and 0.0290.029 lies inside that range \checkmark

It sits near the low end, as expected: the largest supplier also has the lowest defect rate.

Answer

P(D)=0.029\Prob(D) = 0.029, that is 2.9%.

Solved problem 2 · A two-stage experiment

Urn I contains 4 red and 6 blue balls. Urn II contains 7 red and 3 blue balls. A fair coin is tossed: on heads we draw from urn I, on tails from urn II. What is the probability the drawn ball is red?

Step 1 — the partition is the coin toss

P(urn I)=P(urn II)=0.5\Prob(\text{urn I}) = \Prob(\text{urn II}) = 0.5

These are mutually exclusive and exhaustive, so they form a valid partition.

Step 2 — conditional probabilities within each urn

P(RI)=410=0.4,P(RII)=710=0.7\Prob(R \mid \text{I}) = \frac{4}{10} = 0.4, \qquad \Prob(R \mid \text{II}) = \frac{7}{10} = 0.7

Step 3 — combine

P(R)=0.4(0.5)+0.7(0.5)=0.20+0.35=0.55\Prob(R) = 0.4(0.5) + 0.7(0.5) = 0.20 + 0.35 = 0.55

Step 4 — check

With equal weights the answer must be the plain average of 0.4 and 0.7, which is 0.55  0.55 \;\checkmark

Answer

P(red)=0.55\Prob(\text{red}) = 0.55.

Why this matters

The law of total probability is not a standalone trick. It is the denominator of Bayes' theorem, and it appears throughout the curriculum:

  • Bayes' theorem uses it to compute P(A)\Prob(A), the normalising constant.
  • Marginalisation in probabilistic models is this law: summing a joint distribution over the values of a hidden variable.
  • Variable elimination in Bayesian networks applies it repeatedly, which is exactly why that algorithm is tractable.
  • Mixture models define P(x)=kP(xk)P(k)\Prob(x) = \sum_k \Prob(x \mid k)\Prob(k) — a Gaussian mixture is the law of total probability with Gaussian components.

Exercise 1

A student passes an exam with probability 0.9 if they studied and 0.3 if they did not. 70% of students study. What fraction of students pass?

Show solution

Partition on studying, SS and ScS^c, with P(S)=0.7\Prob(S) = 0.7 and P(Sc)=0.3\Prob(S^c) = 0.3 (these sum to 1 ✓).

P(pass)=0.9(0.7)+0.3(0.3)=0.63+0.09=0.72\Prob(\text{pass}) = 0.9(0.7) + 0.3(0.3) = 0.63 + 0.09 = 0.72

Check: 0.720.72 lies between 0.30.3 and 0.90.9 ✓, and closer to 0.90.9 because most students study.

Exercise 2

A box holds 3 fair coins and 1 biased coin that lands heads with probability 0.8. A coin is chosen at random and tossed. Find the probability of heads.

Show solution

Partition on which coin was chosen:

P(fair)=34,P(biased)=14\Prob(\text{fair}) = \tfrac34, \qquad \Prob(\text{biased}) = \tfrac14P(H)=0.5(34)+0.8(14)=0.375+0.200=0.575\Prob(H) = 0.5\left(\tfrac34\right) + 0.8\left(\tfrac14\right) = 0.375 + 0.200 = 0.575

Check: between 0.5 and 0.8 ✓, near the low end since fair coins dominate.

Exercise 3

A student writes: "60% of emails are from known senders and 25% of emails are spam, so P(spam)=P(spamknown)(0.6)+P(spamunknown)(0.25)\Prob(\text{spam}) = \Prob(\text{spam} \mid \text{known})(0.6) + \Prob(\text{spam} \mid \text{unknown})(0.25)." Identify the error.

Show solution

The weights must be the probabilities of the partition cases, not a mix of a case probability and the very quantity being computed.

The partition is {known,unknown}\{\text{known}, \text{unknown}\}, so the weights are 0.60.6 and 10.6=0.41 - 0.6 = 0.4:

P(spam)=P(spamknown)(0.6)+P(spamunknown)(0.4)\Prob(\text{spam}) = \Prob(\text{spam} \mid \text{known})(0.6) + \Prob(\text{spam} \mid \text{unknown})(0.4)

The 0.250.25 is P(spam)\Prob(\text{spam}) itself — the left-hand side. Using it as a weight is circular, and since 0.6+0.25=0.8510.6 + 0.25 = 0.85 \neq 1 the weights do not even form a partition, which is the quickest way to spot the mistake.


Next: Bayes' Theorem — which is this law run backwards, and the single most useful result in the module.