Using a unique dataset on the full student population of 3rd graders in the German state Saarland, we exploit plausibly random variation in class size between cohorts within the same school to estimate the effect of class size on student achievement. Conventional estimates of class size effects are shown to be severely biased by systematic sorting of students between and within schools. Correcting for this, we find that smaller classes are beneficial for language and math test scores and also reduce grade repetition.