Thomas W. Beasley had something for sale, and figured he could market it the same as any other merchandise. “You just sell it like you were selling cars or real estate or hamburgers,” he told an interviewer.

That was three decades ago. Only Mr. Beasley wasn’t hawking new wheels, beachfront property or beef patties. His stock in trade was prison bars. As a co-founder of Corrections Corporation of America in 1983, and with a get-tough-on-crime spirit ascendant in the country, he sold lockup space to federal and state governments that were jailing people faster than they could find room in their own institutions.

[In a new book, an investigative journalist goes undercover as a guard to get behind the scenes of the private prison industry. Read our review.]

Mr. Beasley’s company, renamed CoreCivic two years ago, became a leader in what is now a roughly $4-billion-a-year American industry: for-profit prisons, privately owned and operated. Some bad-to-the-bone criminals are among the people guarded by private prisons. But a key function these days is watching over undocumented immigrants. Their detention centers, located mainly in the South and the West, are where the government sends most people caught trying to enter the United States illegally.

How ably these companies discharge their duty — or not — shapes this Retro Report video, the latest in a documentary series examining major news stories of the past and their continuing impact. The treatment of migrants has new urgency in the Trump era, given this administration’s efforts at strict border control, which include detaining large numbers of children. Data obtained by The New York Times showed that in mid-September, 12,800 migrant children were held in federally contracted shelters, five times the number in custody a little over a year earlier.

One picture of private prisons captured in the video includes barely edible food, indifferent health care, guard brutality and assorted corner-cutting measures. It is framed by the experience of Josue Vladimir Cortez Diaz, a gay man from El Salvador who fled through Mexico to the United States after enduring what he described as persecution and death threats in his homeland. Captured at the California border, he was sent to a private detention center run by GEO Group, formerly the Wackenhut Corrections Corporation. This was in Adelanto, Calif., about 60 miles northeast of Los Angeles.

Mr. Cortez Diaz, 26, was freed after a judge granted him asylum last November, but not before he and other detainees staged a hunger strike to protest their treatment at Adelanto. Prison guards beat and pepper-sprayed them, they say, and they are now suing GEO and federal and local authorities for what they say were rights violations.

“The conditions in the detention center, they’re bad, right down to the food,” Mr. Cortez Diaz told Retro Report. He added, “They don’t care if someone is sick, if the food goes bad. That’s how we came to say we have to protest.”

A spokesman for GEO, Pablo E. Paez, dismissed those assertions as “completely baseless” and said that the federal authorities reviewed that situation and “found that the officers acted in accordance with established protocol.”

Complaints about private prisons are not new. They go back almost to the advent of the prisons themselves in the 1980s. Those were the Reagan years, when government sought to shift some of its functions to private hands. At the same time, voters wanted harsher measures taken against criminals. Thus, cellblock populations rapidly grew, and prisons became alarmingly overcrowded.

But the appetite for locking people up was not matched by a willingness to spend taxpayer money on new government-run cells and support services. Enter for-profit prisons. They were ready to bear some of the burden — for a fee, of course. At federal and state levels, they now operate in more than two dozen states, often in relatively remote regions where jobs can be scarce. It is not unusual in some states for big city crime to become a rural area’s economic development.

The private companies, with CoreCivic and GEO Group dominant, tout their virtues by saying they build and operate prisons more cheaply than governments can, what with the public sector’s many mandates. Their day-to-day operations are similarly more efficient and less costly, they assert, and they do it all without compromising public safety. The bottom line, they say, is that they allow governments to free up public funds for pursuits that mean more to most taxpayers than how felons are jailed.

“Privately operated facilities are better equipped to handle changes in the flow of illegal immigration because they can open or close new facilities as needed,” said Rodney E. King, CoreCivic’s public affairs manager.

Critics tell a different story. They cite moments like a 2015 riot to protest poor conditions at a prison in Arizona run by another major private player, Management & Training Corporation. Earlier at that same institution, three inmates had escaped and murdered two people.

Stories abound of scrimping by prison operators, with bad food and shabby health care for inmates, low pay and inadequate training for guards and hiring shortages. At immigrant detention centers, operators see little need to offer extensive educational programs or job training, since people held there are mostly destined for deportation.

Beyond pragmatic considerations, philosophical questions have dogged private prisons from the start. They boil down to this: If someone violates society’s code of behavior, is it not up to government to punish the offender as society’s representative, and not some profit-seeking entity? As far back as 1985, M. Wayne Huggins, then the sheriff of Fairfax County, Va., asked, “What next will we be privatizing? Will we have private police forces? Will we have private fire departments? Will we have private armies?” Those questions have not disappeared.

Private companies house about 9 percent of the nation’s total prison population. But they take care of a much higher share of immigrant detainees — 73 percent by some accounts. Alonzo Peña, a former deputy director of Immigration and Customs Enforcement, acknowledges that the companies have all too often fallen short. “It wasn’t their priority to ensure that the highest standards were being met,” Mr. Peña said.

ICE, he said, deserves some blame. “We set up this partnership with the private industry in a way that was supposed to make things much more effective, much more economical,” he said. “But unfortunately, it was in the execution and the monitoring and the auditing we fell behind, we fell short.”

Studies suggest that governments save little money, if any, by turning over prison functions to private outfits. And in 2016, under President Barack Obama, the Justice Department concluded that private prisons were in general more violent than government-operated institutions, and ordered a phaseout of their use at the federal level. Reversing that order was one of the first things that President Trump’s attorney general, Jeff Sessions, did on taking office.

The Trump administration leaves no doubt that it will detain as many undocumented immigrants as it can and send them to for-profit centers. And to help make sure that happens, the companies spend millions on campaigns and lobbying efforts (not unlike businesses that sell cars, real estate or hamburgers).

They have thus far figured out how to prevail, a point noted by Lauren-Brooke Eisen, a senior fellow at the Brennan Center for Justice at New York University’s law school. Ms. Eisen explored this in a recent book, “Inside Private Prisons: An American Dilemma in the Age of Mass Incarceration.” Her conclusion: “There is no reason to think the private prison industry will go away anytime soon.”

The video with this article is part of a documentary series presented by The New York Times. The video project was started with a grant from Christopher Buck. Retro Report, led by Kyra Darnton, is a nonprofit video news organization examining the history and context behind today’s news. To watch more, subscribe to the Retro Report newsletter, and follow Retro Report on YouTube and Twitter.

A version of this article appears in print on , on Page A17 of the New York edition with the headline: For Private Prisons, Detaining Immigrants Is a Big Business. Order Reprints | Today’s Paper | Subscribe