On this page
Measure the height of everyone in Class 11 and the numbers spread out. Part of that spread comes from Section A and Section B differing on average; the rest comes from people inside each section differing from one another. The law of total variance says these two parts add up exactly to the total.
What is the law of total variance?
For random variables X and Y, where Y has finite variance, the law of total variance states that Var(Y) = E[Var(Y|X)] + Var(E[Y|X]), as set out in the Wikipedia article on the law of total variance.
E[Var(Y|X)] is the within-group part: find the variance of Y inside each group defined by X, then average those variances.
Var(E[Y|X]) is the between-group part: find the mean of Y in each group, then take the variance of those means.
The same article lists other names for it: the variance decomposition formula, the conditional variance formula, the law of iterated variances and, informally, “Eve's law”, a partner to “Adam's law” for the law of total expectation. If the tower rule E[Y] = E[E[Y|X]] is new to you, read our explainer on the law of total expectation first. It is the main tool the proof needs.
How does it work on real numbers?
Take two sections with four heights each (made-up numbers). Let X be the section and Y the height in centimetres, pick a person at random, and use the population variance (divide by n).
Section A: 150, 154, 158, 162. The mean is 156. The squared deviations are 36, 4, 4 and 36, so the variance is 80/4 = 20.
Section B: 160, 166, 170, 176. The mean is 168. The squared deviations are 64, 4, 4 and 64, so the variance is 136/4 = 34.
Within-group part: the sections are the same size, so E[Var(Y|X)] = (20 + 34)/2 = 27.
Between-group part: the overall mean is 162, and each section mean is 6 cm away from it, so Var(E[Y|X]) = (36 + 36)/2 = 36.
Add them: 27 + 36 = 63.
Now check directly. The eight heights have mean 162 and squared deviations 144, 64, 16, 0, 4, 16, 64 and 196, which sum to 504. Divide by 8 and you get 63. The law holds exactly.
Why is the law of total variance true?
The proof uses one identity and the tower property twice. It follows the general proof in the Wikipedia article above.
Start from Var(Y) = E[Y²] − (E[Y])².
The same identity holds inside each group: E[Y²|X] = Var(Y|X) + (E[Y|X])².
Apply the tower property to E[Y²]: E[Y²] = E[E[Y²|X]] = E[Var(Y|X)] + E[(E[Y|X])²].
Apply it to E[Y]: (E[Y])² = (E[E[Y|X]])².
Subtract: Var(Y) = E[Var(Y|X)] + (E[(E[Y|X])²] − (E[E[Y|X]])²).
The last bracket is E[Z²] − (E[Z])² for Z = E[Y|X], which is Var(E[Y|X]).
Step 6 is the subtle one: E[Y|X] is a function of X, so it has its own variance. Since both parts are never negative, Var(E[Y|X]) can never exceed Var(Y).
If conditional expectation trips you up, the Fermi Concept Library has a lesson for every concept in mathematics, so you can go back one idea and return to the proof.
How is the law of total variance linked to ANOVA and R²?
The Wikipedia article on analysis of variance says that “the underlying principle of ANOVA is based on the law of total variance”. In one-way ANOVA the total sum of squares splits into a between-group and a within-group sum of squares, the sample version of the two terms above. Multiply the example's numbers by 8 and you get the ANOVA split: total 504 = between 288 + within 216. The F-test then asks whether the between part is large compared with the within part, which our one-way ANOVA walkthrough works by hand.
The between part over the total is the share of the spread that the group explains: here 36/63 = 4/7, so knowing someone's section accounts for about 57% of the variance in heights.
In regression, when the prediction is E[Y|X], the law of total variance article gives R² = Var(E[Y|X])/Var(Y) = 1 − E[Var(Y|X)]/Var(Y): the between part over the total. That matches the definition of the coefficient of determination, R², as the proportion of the variation in the dependent variable that is predictable from the independent variable(s).
How do you use the law of total variance in a problem?
Name the variable to condition on (the section, which coin was picked, which machine made the part).
For each value of X, find the conditional mean and the conditional variance of Y.
Average the conditional variances, weighting by P(X = x). That is the within part.
Find the variance of the conditional means, with the same weights. That is the between part.
Add them, and check directly when you can.
When Y is itself a sum, combine this with the rule for the variance of a sum of random variables.
To practise the split on fresh questions, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.



