The common bedbug, Cimex lectularius, feeds not only on humans but on other animals, especially bats. So as well as collecting human-feeders, the researchers gathered bedbugs from bat roosts in houses, churches and castles.

Little was known about the bugs that depend on bats for their meals. “The big thing that this paper adds is the bat side,” said Dr. Fountain, who was not involved in the new study.

Dr. Booth compared DNA sequences from 214 bedbugs. Those that live with bats, he found, were genetically quite distinct from those living with humans.

“The pattern was so stark, I’d never seen anything like it,” Dr. Booth said.

The results support a hypothesis that Dr. Balvin and other researchers have put forward to explain how bedbugs started making life unpleasant for humans. They argue that Cimex lectularius started out living in caves, feeding on bats. When early humans showed up in the caves, some of the bedbugs turned their attention to their new hosts.

“This paper shows that that is true,” Dr. Booth said.

When humans left caves and began building dwellings, they brought their new admirers along. But humans represented a new challenge for the insects, requiring new adaptations.

For one thing, we sleep at night, not in the daytime, which meant that the bedbugs had to shift their schedule. Dr. Balvin and his colleagues also have found that bedbugs that feed on humans have longer, thinner legs than those on bats, perhaps because bedbugs that feed on people no longer need to cling to bats hanging from cave roofs.

The insects also evolved adaptations for feeding on human blood. Researchers at Masaryk University in the Czech Republic have found that bedbugs adapted to feeding on humans have a shorter life span if they drink only bat blood.