Edinburgh scientists say they have developed a genetic test that can tell if people's ancestors were from a large populated area or a rural village.
The team found that a person's DNA records provide a "historical archive" of where they are from.
The test can also detect if a person's ancestors were related, such as if they are from a community where marriage between cousins was commonplace.
It could help identify people who are more prone to genetic illnesses.
A team at Edinburgh University analysed the DNA of more than 1,000 people across 51 different ethnic groups, ranging from Europeans to Amazonian tribes, during the study.
They identified those who had inherited the same genetic material from both parents The study found that native South Americans had the highest amount of shared DNA, suggesting that those communities were small and isolated over many generations.
By contrast, African communities had the lowest degree of genetic similarity, indicating a more diverse population over time.
The team believe this could be explained by the fact that humans originated in Africa and so have had the most time to develop a diverse gene pool.
Dr Jim Wilson, Royal Society research fellow at Edinburgh University, said: "The exciting thing about these results is that it shows our genes are recording the history of movements in our population.
"It's like an archive being written in genetic code, so that we can understand the way our populations have developed from the distant past.
"The findings are also important because it highlights those areas of the world where genetic similarity is common and this can be a risk factor for some diseases like cystic fibrosis, which can be caused when you inherit a faulty gene from both parents."