Family trees dating back to 1600 were studied.
A man's genetic make-up may play a role in whether he has sons or daughters, a study of hundreds of years of family trees suggests.
Newcastle University researchers found men were more likely to have sons if they had more brothers and vice versa if they had more sisters.
They looked at 927 family trees, with details on 556,387 people from North America and Europe, going back to 1600.
The same link between sibling sex and offspring sex was not found for women.
The precise way that genes can influence baby sex remains unproven.
But the Evolutionary Biology study could clear up a long-standing mystery - a flood of boy babies after World War I.
While a woman will always pass a female "X" chromosome via her egg to her child, the father effectively "decides" the sex of the child by passing on either another "X" in his sperm, making a girl, or a "Y" chromosome, making a boy.
While the birthrate is almost 50/50, suggesting that overall men will deliver equal amounts of "X" sperm and "Y" sperm, scientists have suspected that in some individual couples the balance is shifted in favour of either boys or girls.
Various explanations have been put forward for this, ranging from differences in the time in the woman's monthly cycle that sex happens, to the amount of time that sperm spend waiting in the testicles.
The Newcastle study, by Dr Corry Gellatly, is strong evidence that there is a genetic component.
He found that within families, boys with lots of brothers were more likely to have a higher number of sons themselves and those with lots of sisters were more likely to have lots of daughters.
Dr Gellatly said it was likely that a genetic difference affected the relative numbers of "X" and "Y" sperm within those produced by the man.
This gene, while only active in the man, could be carried by men and women.
"The family tree study showed that whether you're likely to have a boy or a girl is inherited."
He said that the effect was to actually balance out the proportion of men and women in the population.
"If there there are too many males in the population, for example, females will more easily find a mate, so men who have more daughters will pass on more of their genes, causing more females to be born in later generations."
In the years after World War I, there was an upsurge in boy births, and Dr Gellatly said that a genetic shift could explain this.
The odds, he said, would favour fathers with more sons - each carrying the "boy" gene - having a son return from war alive, compared with fathers who had more daughters, who might see their only son killed in action.
However, this would mean that more boys would be fathered in the following generation, he said.