In recent years, many countries have experienced a significant expansion of higher education enrolment. There is a particular interest among policy makers for further growth in STEM subjects, which could lead to larger classes in these fields. This study estimates the effect of class size on academic performance of university students, distinguishing between STEM and non-STEM fields. Using administrative data from a large UK higher education institution, we consider a sample of 25,000 students and a total of more than 190,000 observations, spanning seven cohorts of first-year undergraduate students across all disciplines. Our identification of the class size effects rests on within student-across course variation, thus controlling for any unobservable difference across students, albeit other forms of bias stemming from selection of elective courses may still be present. Overall, we find that larger classes are associated with significantly lower grades (effect size of -0.08). This overall effect masks considerable differences across academic fields, as we find a larger effect in STEM subjects (-0.11) than in nonSTEM subjects (-0.04). We further explore the heterogeneity of the effect along the dimensions of students' socio-economic status, ability, and gender, finding that smaller classes are particularly beneficial for students from a low socio-economic background, and within STEM fields for higher ability and male students.