A single gene influences whether breastfeeding improves a child's intelligence, say London researchers.
Children with one version of the FADS2 gene scored seven points higher in IQ tests if they were breastfed.
But the Proceedings of the National Academy of Sciences study found breastfeeding had no effect on the IQ of children with a different version.
The gene in question helps break down fatty acids from the diet, which have been linked with brain development.
Seven points difference is enough to put the child in the top third of the class, the researchers said.
Some 90% of people carry the version of the gene which was associated with better IQ scores in breastfed children.
Researchers at the Institute of Psychiatry, Kings College London, used data from two previous studies of breast-fed infants in Britain and New Zealand, which involved more than 3,000 children.
IQ was measured at various points between the ages of five and 13 years in the studies.
Previous studies on intelligence and breastfeeding have come up with conflicting results.
There has been some debate as to whether mothers who had more education or who were from more affluent backgrounds were more likely to breastfeed, skewing the results.
Professor Terrie Moffitt, a co-author on the paper, said the findings gave a fresh perspective on the arguments by showing a physiological mechanism that could account for the difference between breastfed and bottle-fed babies.
"The argument about intelligence has been about nature versus nurture for at least a century," she said.
"However, we have shown that in fact nature works via nurture to create better health outcomes."
Since the studies used in the analysis were done, manufacturers have begun to add fatty acids to formula milk but there have been inconsistent results on the benefits.
Belinda Phipps, of the National Childbirth Trust, said: "This shows for the majority of parents they can have a positive effect on their babies IQ by breastfeeding."
Catherine Collins, a dietician at St Georges Hospital in London and spokesperson for the British Dietetic Association, said the study highlighted the interaction between nutrition and genetics.
"In this study you have an effect that suggests that nature is more important that nurture.
"If nine out of 10 babies benefit, then that is a very good chance."
But she added the study did not specify how long babies were breastfed for and it may be that even breastfeeding for a short period may be beneficial for intelligence.
Professor Jean Golding, who founded the ALSPAC study set up in the 1990s to follow the development of thousands of children in the South West of England, said the results were fascinating and they would be doing a further study of the gene.
"In the past people have had different results about whether breastfeeding improves IQ and this would sort out the reason why," she said. ( BBC )