Hypovitaminosis D has been linked with poor cognitive function, particularly in older adults, but studies lack a lifespan approach; hence, the effects of reverse causality remain unknown. In the present study, we aimed to assess the relationship between 25-hydroxyvitamin D (25(OH)D) concentrations and subsequent cognitive performance in mid-adulthood and the influence of earlier life factors, including childhood cognitive ability, on this association. Information for the present study was obtained from the members of the 1958 British birth cohort (n 6496). Serum 25(OH)D concentration, indicating vitamin D status, was measured at age 45 years. Verbal memory (immediate and delayed word recall), verbal fluency (animal naming) and speed of processing were tested at age 50 years. Information on childhood cognitive ability, educational attainment, vitamin D-related behaviours and other covariates was collected prospectively from participants throughout their life. Childhood cognitive ability and educational attainment by age 42 years were strongly correlated with cognitive performance at age 50 years and with several vitamin D-related behaviours in mid-adulthood, but not with 25(OH)D concentrations at age 45 years. Participants with both low ( < 25 nmol/l) and high ( ≥ 75 nmol/l) 25(OH)D concentrations at age 45 years performed significantly worse on immediate word recall. The associations attenuated after adjustment for childhood cognitive ability, education, and socio-economic position; however, for the immediate word recall test, there was a non-linear association with 25(OH)D after further adjustment for obesity, menopausal status, smoking, alcohol consumption, physical activity and depressive symptoms at age 45 years (Pcurvature= 0·01). The present study demonstrated that 25(OH)D concentrations were non-linearly associated with immediate word recall in mid-life. A clarification of the level of 25(OH)D concentrations that is most beneficial for predicting better cognitive performance in mid-life is required.