And in New York, when patients are discharged — typically after about five days — the needed transition to an outpatient treatment program often never occurs. That is one reason many patients do not fully recover from their addictions and return to detox wards, experts say.

The system suits the most frequent patients — most of them homeless, mentally ill, or both — who see the programs as a source of shelter and food. And the most expensive treatment, which usually involves some sedation, can reduce the discomfort of withdrawal better than other methods.

Some drug users, especially those on opiates, also set out to clean their systems so they can reduce the dose needed to get high, according to addicts and those who treat them. For a homeless addict, the cost of each dose is a major concern.

But at its core, experts say, the overuse of costly inpatient programs is connected to the lack of housing for homeless people. People are less likely to admit themselves to hospitals, and more likely to adhere to treatment programs, when they are not living on the streets. For more than a decade, the city and state have invested in such housing, including some that accept residents who are not yet drug-free, but demand for housing still far exceeds supply.

“For this small group of what are basically professional inpatient detoxification users, it’s really a whole series of linked problems, and none of the parts of the system work very well,” said Dr. Richard N. Rosenthal, an addiction specialist and chairman of psychiatry at St. Luke’s-Roosevelt Hospital Center in Manhattan. “There’s been some progress on each element, but not enough.”

The most intensive form of treatment, “medically managed” withdrawal takes place in a hospital, usually involves some sedation, and requires a great deal of care by doctors and nurses. The next level, “medically supervised withdrawal,” can be done in a hospital, or sometimes on an outpatient basis, and requires less medical intervention and less staff.

In New York, Medicaid pays an average of more than $100 a day for outpatient medically supervised withdrawal, and close to $400 a day for the inpatient version.