It is easy to see why AIDS seemed so mysterious and frightening when US medics first encountered it 35 years ago. The condition robbed young, healthy people of their strong immune system, leaving them weak and vulnerable. And it seemed to come out of nowhere.

Today we know much more how and why HIV – the virus that leads to AIDS – has become a global pandemic. Unsurprisingly, sex workers unwittingly played a part. But no less important were the roles of trade, the collapse of colonialism, and 20th Century sociopolitical reform.

HIV did not really appear out of nowhere, of course. It probably began as a virus affecting monkeys and apes in west central Africa.

From there it jumped species into humans on several occasions, perhaps because people ate infected bushmeat. Some people carry a version of HIV closely related to that seen in sooty mangabey monkeys, for instance. But HIV that came from monkeys has not become a global problem.

It seems that this form of HIV simply took advantage of events

We are more closely related to apes, like gorillas and chimpanzees, than we are to monkeys. But even when HIV has passed into human populations from these apes, it has not necessarily turned into a widespread health issue.

HIV originating from apes typically belongs to a type of virus called HIV-1. One is called HIV-1 group O, and human cases are largely confined to west Africa.

In fact, only one form of HIV has spread far and wide after jumping to humans. This version, which probably originated from chimpanzees, is called HIV-1 group M (for "major"). More than 90% of HIV infections belong in group M. Which raises an obvious question: what's so special about HIV-1 group M?

A study published in 2014 suggests a surprising answer: there might be nothing particularly special about group M.

It is not especially infectious, as you might expect. Instead, it seems that this form of HIV simply took advantage of events. "Ecological rather than evolutionary factors drove its rapid spread," says Nuno Faria at the University of Oxford in the UK.

Faria and his colleagues built a family tree of HIV, by looking at a diverse array of HIV genomes collected from about 800 infected people from central Africa.

The very first person to be infected with HIV-1 group M probably picked up the virus in the 1920s

Genomes pick up new mutations at a fairly steady rate, so by comparing two genome sequences and counting the differences they could work out when the two last shared a common ancestor. This technique is widely used, for example to establish that our common ancestor with chimpanzees lived at least 7 million years ago.

"RNA viruses such as HIV evolve approximately 1 million times faster than human DNA," says Faria. This means the HIV "molecular clock" ticks very fast indeed.

It ticks so fast, Faria and his colleagues found that the HIV genomes all shared a common ancestor that existed no more than 100 years ago. The HIV-1 group M pandemic probably first began in the 1920s.

Then the team went further. Because they knew where each of the HIV samples had been collected, they could place the origin of the pandemic in a specific city: Kinshasa, now the capital of the Democratic Republic of Congo.

At this point, the researchers changed tack. They turned to historical records to work out why HIV infections in an African city in the 1920s could ultimately spark a pandemic.

A likely sequence of events quickly became obvious.

Everything was in place for an explosion in infection rates in the 1960s

In the 1920s, DR Congo was a Belgian colony and Kinshasa – then known as Leopoldville – had just been made the capital. The city became a very attractive destination for young working men seeking their fortunes, and therefore also for sex workers. The virus spread quickly through the population.

It did not remain confined to the city. The researchers discovered that the capital of the Belgian Congo was, in the 1920s, one of the best connected cities in Africa. Taking full advantage of an extensive rail network used by hundreds of thousands of people each year, the virus spread to cities 900 miles (1500km) away in just 20 years.

Everything was in place for an explosion in infection rates in the 1960s.

The beginning of that decade brought another change.

The story of the spread of HIV is not over yet

Belgian Congo gained its independence, and became an attractive source of employment to French speakers elsewhere in the world, including Haiti. When these young Haitians returned home a few years later they took a particular form of HIV-1 group M, called "subtype B", to the western side of the Atlantic.

It arrived in the US in the 1970s, just as sexual liberation and homophobic attitudes were leading to concentrations of gay men in cosmopolitan cities like New York and San Francisco. Once more, HIV took advantage of the sociopolitical situation to spread quickly through the US and Europe.

"There is no reason to believe that other subtypes would not have spread as quickly as subtype B, given similar ecological circumstances," says Faria.

The story of the spread of HIV is not over yet.

For instance, in 2015 there was an outbreak in the US state of Indiana, associated with drug injecting.

The US Centers for Disease Control and Prevention has been analyzing the HIV genome sequences and data about location and time of infection, says Yonatan Grad at the Harvard School of Public Health in Boston, Massachusetts. "These data help to understand the extent of the outbreak, and will further help to understand when public health interventions have worked."

This approach can work for other pathogens. In 2014, Grad and his colleague Marc Lipsitch published an investigation into the spread of drug-resistant gonorrhoea across the US.

"Because we had representative sequences from individuals in different cities at different times and with different sexual orientations, we could show the spread was from the west of the country to the east," says Lipsitch.

What's more, they could confirm that the drug-resistant form of gonorrhoea appeared to have circulated predominantly in men who have sex with men. That could prompt increased screening in these at-risk populations, in an effort to reduce further spread.

In other words, there is real power to studying pathogens like HIV and gonorrhoea through the prism of human society.