We examine whether the sorting of differently achieving students into differently sized classes results in a regressive or compensatory pattern of class sizes for a sample of national school systems. Sorting effects are identified by subtracting the causal effect of class size on performance from their total correlation. Our empirical results indicate substantial compensatory sorting within and especially between schools in many countries. Only the United States, a country with decentralized education finance and considerable residential mobility, exhibits regressive between-school sorting. Between-school sorting is more compensatory in systems with ability tracking. Within-school sorting is more compensatory when administrators rather than teachers assign students to classrooms.