Four classes: 8, 40, 40 and 12. That is a hundred students in four classes, so the school reports 25. Now line the hundred students up and ask each one how big their class is. Eight say 8. Forty say 40. Forty say 40. Twelve say 12. That averages 34.08.
Neither number is wrong, and they come off the same roll. A big class simply contains more students to be asked.
The gap is not a fudge or an approximation. It is exact:
weighted mean − plain mean = cov(value, weight) ÷ mean(weight)
and when the weight is the value: variance ÷ mean
Two things follow from that directly. The two averages agree only when every group is exactly the same size, because that is the only time the variance is zero. And the weighted one can never be the smaller of the two, because a variance cannot be negative — which is why “the average class size” always sounds better than the thing anyone is actually sitting in.
This is in most statistics that are collected per-thing and lived per-person. Bus waits, hospital stays, invoice payment days, server latency, flight loads, restaurant tables. Nothing is stored: this page has no database and no session.
Your rows
Both come off the same 5 rows and neither is wrong. Counting classes, every class is counted once. Counting students, a class with more students in it is counted more often — which is why the two differ by 3.9, or 18%.
Every row, to scale
Each class is a rectangle: how tall it is is what it measures, how wide it is is how many students are in it. The lower line is the average height. The upper line is the average height of the area — which is the same thing as asking a student.
Where the gap comes from
| Class | Value | Students | Share | Of the gap |
|---|---|---|---|---|
| Year 13 calculus | 8.0 | 8 | 7% | 46% |
| Year 9 maths | 31.0 | 31 | 28% | 19% |
| Year 12 statistics | 14.0 | 14 | 13% | 15% |
| Year 10 English | 29.0 | 29 | 26% | 12% |
| Year 11 science | 28.0 | 28 | 25% | 8% |
| The gap | 25.87 − 22.00 | 3.87 | ||
The contributions sum to the gap exactly, not approximately — each one is (value − mean)(weight − mean weight) over n times the mean weight, which is the covariance taken apart row by row.
That is an identity, not an approximation — it holds for any set of numbers at all. Two consequences follow from it directly. The two averages agree only when every class is exactly the same size, because that is the only time the variance is zero. And the student average can never be the smaller of the two, because a variance cannot be negative. So "the average class size" always sounds better than the thing anyone is actually in.
The same split, done with medians instead of means, so no single large class can be blamed for it. If somebody objects that one enormous class is dragging the average, this is the answer: take the middle one and the gap is still there, because it was never about an outlier. It is about how many students each class contains.
It holds 7% of the students and sits below the class average. When the weight is the value, a class pushes the two averages apart by differing from the average at all — in either direction, because each contribution is a squared deviation and nothing can pull them back together. Every row's contribution is in the table, and they sum to the gap exactly rather than approximately — which is what makes the ranking worth reading rather than worth glancing at.
If you are asking how many students there are per class — a budget question, a staffing question — the class average, 22.0, is the one that answers it. If you are asking what it is like to be a student, the student average, 25.9, is. Reporting the first and describing the second is the common mistake, and it is common because the first is the one that falls out of the accounts.
Bus timetables: buses every ten minutes, and the average passenger waits longer than five, because more of them turn up during the long gaps. Hospital stays: the average admission is short, and the average bed on any given day is holding a long one. Invoices: the average one is paid quickly and the average dollar waits, because the big invoices go to the slow payers. Server latency, flight loads, restaurant tables, prison sentences. Wherever the thing being counted and the thing doing the experiencing are different, this gap is there, and it is always in the same direction.
What it does not know
It cannot tell you which average to publish. That depends on the question, and the page says so rather than picking. If you are budgeting for teachers, the per-class figure is the one that answers you. If you are describing what school is like, the per-student one is. The mistake is reporting the first and describing the second, and it is common because the first is the one that falls out of the accounts.
It assumes the rows are the whole population. The variance here is divided by n, not n−1, because this is a property of the groups in front of us rather than an estimate of some wider population’s spread — and the identity only holds in that form. If your rows are a sample of a larger set, both averages are estimates and neither carries an interval here.
It does not know whether your weights are the right weights. Weighting invoice days by dollars answers “how long does the average dollar wait”. Weighting them by invoice count answers a different question, and weighting them by customer answers a third. All three are defensible; only one of them is what you meant.
An average of any kind is a poor summary of a lopsided set. Both figures here are means, and both are pulled by the far end. The medians are given for exactly that reason — when they show the same split, no single outlier can be blamed for it.
It has no view on whether the spread should be there. Whether classes of 8 and 40 in the same school is good or bad is not a question arithmetic answers. What the arithmetic says is only that the two numbers differ, by exactly this much, and why.