The United States as a whole has about 87 people for each square mile. New York City’s human habitat, however, is entirely different. In Manhattan, more than 70,000 people cram into the same space. From subways to sky-high offices, they scurry to and fro, creating something like a giant ant mound — which is precisely what you will find if you zoom in close enough on Manhattan’s sparse patches of soil.

According to a new study published in the journal Insect Conservation and Diversity, at least 42 species of ants call New York City home — although that figure is probably low. “Biodiversity surveys are snapshots,” said the lead author, Amy Savage, a biologist at North Carolina State University. “But we still got way more species than I expected.”

Dr. Savage and her colleagues sampled 32 sites north of 59th Street in Manhattan, including urban parks, forests found within parks and vegetated road medians along Broadway. Not surprisingly, the medians harbored the fewest ant species, while the forests had the most.

But contrary to expectations, the ants’ tiny size did not limit their ability to get around town. Instead of colonizing places that were nearby, the same types of species tended to pop up in the same types of habitats, regardless of the distance between them. For example, even though the urban Morningside Park is relatively close to Central Park’s forests, the ants living in Central Park were more similar to those living many blocks north, in the forests of Inwood Hill Park.