The impact of class size on student achievement remains a thorny question for educational decision makers. Meta-analyses of empirical studies emphasise the absence of class-size effects but detractors have argued against such pessimistic conclusions because many of the underlying studies have not paid attention to the endogeneity of class-size. This paper uses a stringent method to address the endogeneity problem using TIMSS data on 45 countries. We measure the class size effect by relating the difference in a student's achievement across subjects to the difference in his/her class-size across subjects. This (subject-differenced) within-pupil achievement production function avoids the problem of the non-random matching of children to specific schools, and to classes within schools. The results show a statistically significant effect of class size for 16 countries but in only 10 of them is the effect negative, and the effect size is very small in most cases. Several robustness tests are carried out, including control for students' subject-specific ability and subject-specific teacher characteristics, and correction for possible measurement error. Thus, our stringent approach to addressing the problem endogeneity confirms the findings of meta-analyses that find little support for class size effects. We find that class-size effects are smaller in resource-rich countries than in developing countries, supporting the idea that the adverse effect of larger classes increases with class-size. We also find that class size effects are smaller in regions with higher teacher quality.