Our aim was to investigate whether the duration of breastfeeding, at all or exclusively, is associated with educational achievement at age 5. We used data from a prospective, population-based UK cohort study, the Millennium Cohort Study (MCS). 5489 children from White ethnic background born at term in 2000–2001, attending school in England in 2006, were included in our analyses. Educational achievement was measured using the Foundation Stage Profile (FSP), a statutory assessment undertaken by teachers at the end of the child's first school year. Breastfeeding duration was ascertained from interviews with the mother when the child was 9 months old. We used modified Poisson's regression to model the association of breastfeeding duration with having reached a good level of achievement overall (≥78 overall points and ≥6 in ‘personal, social and emotional development’ and ‘communication, language and literacy’ points) and in specific areas (≥6 points) of development. Children who had been breastfed for up to 2 months were more likely to have reached a good level of overall achievement [adjusted rate ratio (RR): 1.09, 95% confidence interval (CI): 1.01, 1.19] than never breastfed children. This association was more marked in children breastfed for 2–4 months (adjusted RR: 1.17, 95% CI: 1.07, 1.29) and in those breastfed for longer than 4 months (adjusted RR: 1.16, 95% CI: 1.07, 1.26). The associations of exclusive breastfeeding with the educational achievement were similar. Our findings suggest that longer duration of breastfeeding, at all or exclusively, is associated with better educational achievement at age 5.