Young people's wellbeing is often lowest where they assume a relatively low position within their school's socioeconomic hierarchy, for example, among poorer children attending more affluent schools. Transition to secondary school is a period during which young people typically enter an environment which is more socioeconomically diverse than their primary school. Young people joining a school with a higher socioeconomic status intake relative to their primary school may assume a relatively lowered position within their school's socioeconomic hierarchy, experiencing a detriment to their wellbeing as a consequence. This article draws on data from 45,055 pupils in Years 7 and 8, from 193 secondary schools in Wales, who completed the 2017 Student Health Research Network (SHRN) Student Health and Wellbeing (SHW) survey. Pupils reported which primary school they previously attended, and survey data on wellbeing were linked to publicly available data on the free school meal entitlement of schools attended. In cross-classified linear mixedeffects models, with primary and secondary school as levels, mental wellbeing varied significantly according to both primary and secondary school attended. A higher school-level deprivation was associated with worse mental wellbeing in both cases. Mental wellbeing was significantly predicted by the relative affluence of a child's primary and secondary school, with movement to a secondary school of higher overall socioeconomic status associated with lowered wellbeing. These findings highlight transition to secondary school as a key point in which socioeconomic inequality in wellbeing may widen, and thus as an important focal point for intervention to reduce health inequalities.