Mosquitoes have been called the deadliest animal in the world: tiny creatures so dangerous that genetic engineering may be necessary to win the battle against them. But not all mosquitoes are equally responsible for devastating the human population by spreading disease. Out of thousands of species, only a few like to bite humans — and even within the same species, mosquitoes from different places can have different preferences. Why do some find us irresistible, while others remain unimpressed?

To answer that question, a team of Princeton researchers, working with a large network of local collaborators, spent three years driving around sub-Saharan Africa collecting the eggs of Aedes aegypti mosquitoes, which are responsible for Zika, yellow fever and dengue.

There are two subspecies of Aedes aegypti: one that prefers humans and one that prefers animals; most populations are a genetic mix. After sending the eggs to New Jersey to grow new colonies, and then tempting the insects with the sweet smells of human and of rodent, the researchers found that the more human-loving mosquitoes tended to come from areas with a dry climate and dense human population. That, in turn, is because humans provide the water mosquitoes need to breed.

“There had been quite a bit of speculation in the literature that the original reason this species evolved to be a human specialist had to do with its use of human water,” said Lindy McBride, a Princeton neuroscientist and an author on the study. “It’s easy to come up with hypotheses, but what was incredibly surprising was that you could actually see evidence for that.”

Like all mosquitoes, Aedes aegypti lays its eggs on water, so the project began by setting out thousands of ovitraps, little plastic cups lined with seed paper and filled with water and dirty leaves to simulate the ideal breeding environment. (For cups, the team employed the kind that casinos give out to hold poker chips.)

The ovitraps were placed in big cities and in rural areas, in an effort to span environmentally diverse locations, said Noah H. Rose, a postdoctoral fellow at Princeton and co-author of the study published on Thursday in Current Biology. A few days later, someone came back and checked for eggs.

Not all of the expeditions were successful. “Sometimes you’d speed weeks in a place and just didn’t get any eggs,” Dr. Rose said. But in all, the team collected eggs from 27 locations. Once dried, the eggs were akin to seeds; they could lie dormant for six months or a year before being hatched, and so were brought back from all across Africa to the Princeton lab to be bred.

After new colonies were established, the next step was figuring out why some populations evolved to become generalists and some to become so-called human specialists. This required deploying an olfactometer: a big plastic box full of mosquitoes, with two removable tubes in it, one containing a guinea pig (or, occasionally, a quail ordered from a farm) and the other holding part of a human.

“I was just sitting with my arm in the tube doing this trial over and over again,” Dr. Rose said. He spent “a couple months of my life” as mosquito bait, repeating the experiment hundreds of times while listening to audiobooks. (A favorite was Anna Burns’ “Milkman,” about The Troubles in Ireland. Screens kept him and the guinea pig from actually being bitten.)

Within minutes, mosquitoes, attracted to either the human or the nonhuman scent, would pick a tube and enter it. Later, the tubes were removed to count the mosquitoes and figure out how many preferred Dr. Rose.

The resulting data revealed that mosquitoes that originally came from very dense areas — more than 5,000 people per square mile — liked humans more. (They also had more ancestry from the human-preferring subspecies.) A bigger factor, however, was climate. Specifically, mosquitoes that came from places that had a rainy season followed by a long, hot, dry season greatly preferred humans.

Why? The scientists proposed an explanation that Brian Lazzaro, a professor of entomology at Cornell University who was not involved with the study, called “pretty convincing.” Mosquitoes flourish during the rainy season, but then must find a way to survive the dry season. Standing water, critical for mosquitoes to breed, is hard to come by in extremely arid environments. But it can be found around humans, who store water to live, and so mosquito populations from arid regions evolved to take advantage of the situation.

Dr. Lazzaro also praised the team for sequencing the mosquitoes. That procedure revealed that the human-loving mosquitoes were genetically distinct from the animal-loving ones, and found that the preference for humans developed at one location and then spread across Africa. “They really see a single origin of these human-feeding mosquitoes,” he said. “That is a little surprising to me,” he added, because there plausibly could have been multiple instances of genetic adaptation.

The Current Biology paper focused on evolutionary history, but its findings might have implications for public health. The results, combined with climate and population data from the United Nations, suggest that there will be more human-biting mosquitoes in sub-Saharan Africa by 2050, caused mostly by urbanization.

“I think it’s counterintuitive, because people know the climate is changing rapidly, so that should be the driving force,” Dr. McBride said. “But the features of the climate that we found to be important for this mosquito aren’t predicted to change in strong and clear ways that would affect the mosquito.”

Urbanization, in contrast, is occurring very quickly. “You could easily imagine that having an effect on disease transmission in big cities,” Dr. McBride said.

The new paper is a “major achievement,” said Niels O. Verhulst, an entomologist at the University of Zurich in Switzerland who was not involved in the study. In 2003, Dr. Verhulst gathered for review many different papers on mosquito host preference; he quickly found that they all used different methodologies that made them hard to compare. That the current study investigated so many different sites was therefore impressive, he said. And it underscored how important it is for cities to proactively remove possible mosquito breeding sites.

Dr. Rose said that the team planned to conduct follow-ups in other sites in Africa, and to study the brains of the human-specialist mosquitoes to figure out the specific mechanisms that make them love our odor so much. When it comes to mosquitoes, there’s much more to learn. “Their history is intertwined with our history,” he said. “And mosquitoes are one of the most interesting ways to understand how human and nature are linked together in the contemporary world.”

[Like the Science Times page on Facebook. | Sign up for the Science Times newsletter.]