When Latrell Head, a 32-year-old single father in Atlanta, entered a nursing home after a leg amputation in October, workers there for a while would not allow him to leave to see his 8-year-old son or search for an apartment. Such facilities typically require relatives to sign residents out. “A prisoner has more rights than I have,” he said he felt.

Mariussi Ogando-Rodriguez, 29, said she feels lonely among the hundreds of mostly older residents at the Manhattan nursing center where she has lived for three years. A former accounting student and cashier at Chipotle, she needs dialysis three times a week, but could care for herself. Gesturing toward a group of people watching television last week in a recreation room that smelled like urine, she said, “Sometimes I feel desperate.”

A range of factors conspire to prevent residents from leaving. In many states, Medicaid programs restrict home health services, limiting the hours of care, for example. Waiting lists are common. Mentally ill people, for whom nursing homes are shelters of last resort, are particularly difficult to place. And everywhere, it seems, affordable, accessible housing for disabled people is in short supply.

Living at home is not the right choice for everyone, of course, even with assistance. Some people are too ill. Managing aides can be daunting, and family members might not be able — or willing — to care for relatives or share their homes, particularly when cognitive skills are impaired. For those without family, living alone can be isolating.

Still, about half of Medicaid spending on long-term care now goes toward services in the home or community, compared with less than 20 percent two decades ago, though that varies widely by state. Health care officials predict demand for in-home services will only grow as the population ages. Emily Johnson Piper, commissioner of the Minnesota Department of Human Services, said, “The baby boomers in Minnesota and across the country have the expectation that they will be offered and afforded availability of services for them to live out their retirement years in their communities.”

Many states have concluded that caring for people at home is more cost-effective. Washington State, for example, has found that its costs for one nursing home resident would pay for home care for seven people. Alabama calculated that it cost the state about $25,000 a year less, per person, to offer care at home.