But almost as long as there has been heroin in the United States, New York City has been its hub. Certainly much has changed since the 1970s, when addicts flooded shooting galleries and flashy drug traffickers like Nicky Barnes, known as Mr. Untouchable, became household names. The drug is still smuggled into the country from faraway poppy fields, still cut from kilo-size quantities in hothouse operations secreted around the city, still diluted in coffee grinders and still sold to needy consumers.

Various brands, too, have been around for decades. “There always have been markings going back as far as Nicky Barnes,” said James J. Hunt, the acting head of the Drug Enforcement Administration’s New York office. “Now the difference is that the addicts you see a lot are young suburban kids starting on prescription drugs, and they graduate to heroin.”

The trade has become more organized, officials said, from the top to the bottom. Delivery services abound for those who can afford a dealer who arrives at the door with a grab bag of drugs. Highly organized mills have been found in middle-class city areas like Riverdale, in the Bronx, and Fort Lee, N.J., or, in one case, in a Midtown Manhattan apartment near the Lincoln Tunnel. Such locations draw less scrutiny from potential robbers, and often provide ready access to major roads for deliveries up and down the Eastern corridor.

“It’s like somebody setting up a big production factory in China and the product is going to go out through to the world,” Ms. Brennan said. “That’s how I look at these production mills that we’re seeing in New York. Some will stay here in the city, but it’s mostly intended for distribution.” (A $6 bag in the city could fetch as much as $30 or $40 in parts of New England, authorities have said.)

Some officials fear that efforts to drive down abuse of prescription medications could be contributing to rising heroin use in New York City, as it has in places like Maine.

“What we’re seeing, as pills become more difficult to access, is a shift to the black market and heroin,” said Dr. Andrew Kolodny, the chief medical officer at the Phoenix House Foundation, a drug-treatment center, and president of Physicians for Responsible Opioid Prescribing. “It’s not easy to get the opioid genie back into the bottle.”

Image Bags bearing different stamps, like Twilight, turn up in raids around the city. Credit... Drug Enforcement Agency

It is a cycle that friends of Mr. Hoffman, who was 46, said may have recently taken hold in his life as well.