Socioeconomic disadvantage at individual level is associated with poor cognitive outcomes but the link of neighbourhood disadvantage with cognitive function is unclear. We used data from Young Finns Study, a population-based cohort, to examine the associations of neighbourhood and individual-level disadvantage in childhood (age 3-21 years) and adulthood (age 22 up to the time of cognitive assessment) with cognitive function in mid-adulthood (age 35-49 years). Neighbourhood disadvantage was ascertained based on register data, including geo-coded address history. Compared to individuals who experienced neither individual-level nor neighbourhood disadvantage in childhood, those who experienced both had, on average, 0.236 standard deviations (SDs) lower overall cognitive function scores (95% confidence interval, CI: -0.355 to -0.116) and those who experienced individual-level but not neighbourhood disadvantage had 0.196 SDs lower scores (95% CI: -0.323 to -0.070). The estimates were slightly larger for adult individual-level and neighbourhood disadvantage. The findings were similar across the cognitive domains and robust to adjustment for a polygenic risk score for cognitive ability. We found no clear evidence of sleep difficulties, depressive symptoms or cardiovascular health mediating the associations. Our findings suggest that socioeconomic disadvantage at individual- but not neighbourhood-level, from childhood to adulthood, may impact on cognitive function in mid-adulthood.