The two men were very different. Mr. Rajaratnam was a high-rolling hedge fund manager who loved to take risks, while Mr. Gupta was a consultant educated at Harvard Business School who worked all his life at one firm, McKinsey & Company.

Years after their closely watched insider trading trials and two of the biggest victories for prosecutors in the government’s crackdown on insider trading on Wall Street, the men find themselves under the same roof: In a new development, both are now at the main prison at the Federal Medical Center Devens in Ayer, Mass., northwest of Boston, with 1,000 other inmates.

Friends, a former inmate and those who have interacted extensively with the two men describe what has become an awkward relationship. The two lead parallel lives that sometimes intersect. They occasionally run into each other in the common areas at Devens and exchange pleasantries.

Although both men are in prison for the same crime, their friendship is irrevocably broken.

It is a long way from the chummy relationship Mr. Rajaratnam worked to cultivate over the years with Mr. Gupta and a web of others in corporate America as, prosecutors say, he worked to obtain illegal insider tips for his now-defunct hedge fund, the Galleon Group. Mr. Gupta played a pivotal part, providing an important tip about Goldman Sachs’s financial health during the depths of the 2008 financial crisis.

That affinity, however, quickly frayed as both men stood trial. Mr. Rajaratnam was sentenced to 11 years in federal prison in 2011 after his conviction on 14 counts of conspiracy and securities fraud. Mr. Gupta was convicted in 2012 on one count of conspiracy and three counts of securities fraud.

David E. Morgan, a former inmate who served about a year and half on charges related to insurance fraud, met both men at Devens. Initially, Mr. Gupta was rumored to be a snitch, Mr. Morgan said.

But Mr. Gupta quickly won over inmates. “People would ask him about trading stocks,” Mr. Morgan said, and Mr. Gupta would reply: “I don’t know anything about stocks.”

Often, before their release, inmates would seek Mr. Gupta’s advice on business plans. One even asked him to invest. According to Mr. Morgan, Mr. Gupta replied: “I am out of business.”

Though Mr. Gupta earned inmates’ respect, prison conditions can seem harsh to those accustomed to civilian life. White-collar convicts are typically treated better than murderers, but the main prison in Devens houses inmates of all security levels; until recently, it was home to Dzhokhar Tsarnaev, the Boston Marathon bomber.

Image

Both Rajat Gupta and Raj Rajaratnam are now at the main prison at the Federal Medical Center Devens in Ayer, Mass., the same facility that once housed Dzhokhar Tsarnaev, the Boston Marathon bomber.CreditElise Amendola/Associated Press

When Mr. Gupta arrived in June 2014, he was assigned to Devens’s minimum security camp, which houses 135 inmates. But in April, Mr. Gupta was sent for six weeks to the Special Housing Unit, or SHU (pronounced “shoe,” as fans of the Netflix series “Orange Is the New Black” know), as punishment. His infraction was having an unauthorized item: an extra pillow.

Inmates often grab the pillows of departing prisoners. Mr. Gupta hoped an extra pillow would help with a bad back.

It is just one sign of the long fall from grace for Mr. Gupta. After his trial, luminaries like Bill Gates and Kofi Annan, the former United Nations secretary general, wrote admiringly to the judge about Mr. Gupta’s charity work to urge leniency. Still, the judge sentenced Mr. Gupta, a former Goldman director, to two years in prison, calling his 2008 insider tip — in which he disclosed Warren E. Buffett’s investment in the financial firm — “a terrible breach of trust.”

It was the second time that Mr. Gupta was sent to “the hole,” as the SHU is sometimes called. Last summer, Mr. Gupta was dispatched to the unit for sitting during the inmate count.

“He was actually tying his shoe,” Mr. Morgan said.

Inmates in the unit are kept in near solitary conditions. They are allowed out of their cells only for one hour of exercise a day, said Michael Santos, a former federal prisoner who is now a consultant. A light is on 24 hours a day for observation.

When inmates are moved for a visit, they must wear orange jumpsuits and are restrained in an elaborate procedure. “There is a cutout door within the cell door,” Mr. Santos said, through which inmates are also fed. “The inmate is told to back step to the door, squat down, and then he will be told to put his arms behind his back, and through that slot, the guard will put handcuffs on him,” he said.

The guard opens the door only when the inmate has been cuffed.

At a disciplinary hearing in May, Mr. Gupta’s privileges such as visiting rights were revoked, people briefed on the situation said. When Mr. Gupta’s elder sister traveled from India to see him, he offered to serve more time if she could visit, these people said. His requests were denied. She returned to India without seeing her brother.

Shortly after, Mr. Gupta was transferred to the main compound.

When Mr. Morgan, the former inmate, arrived at the compound in October 2013, Mr. Rajaratnam, a longtime diabetic who needs dialysis, was housed in the prison’s hospital in a comfortable electrically operated bed. After a stint in the camp, when Mr. Morgan returned to the main prison compound late last year, he noticed that Mr. Rajaratnam “was in the same unit as I was” — a unit made up of two-man cells with a toilet, a sink, two lockers, one desk and narrow bunk beds.

Mr. Morgan said Mr. Rajaratnam asked about Mr. Gupta, saying: “I consider him my friend.” Mr. Morgan responded: “He doesn’t consider you his friend.” Mr. Rajaratnam persisted. “Listen, you need to know I had an opportunity to give up Gupta and I didn’t,” he said.

Reed Brodsky, the prosecutor, did make an overture in August 2011 for the hedge fund manager to cooperate. It was widely known that charging Mr. Gupta was a priority for prosecutors. Mr. Rajaratnam, through his lawyer, turned Mr. Brodsky down.

Samidh Guha, Mr. Rajaratnam’s lawyer, said his client recalled meeting with Mr. Morgan for a few minutes. “Mr. Rajaratnam simply told Mr. Morgan that Mr. Gupta is a good man and is innocent,” Mr. Guha said.

Image

Raj Rajaratnam, formerly of the Galleon Group, is at the same facility in Ayer, Mass., as Mr. Gupta.CreditJin Lee/Associated Press

In court papers filed in June to set aside Mr. Rajaratnam’s conviction, his lawyers claimed that Anil Kumar, a McKinsey consultant who had testified against Mr. Rajaratnam and his brother Rengan, had lied under oath.

Gregory Morvillo, Mr. Kumar’s lawyer, strongly disagreed with their assertions. He acknowledged that Mr. Rajaratnam’s wife, Asha, recently contacted Mr. Kumar and asked him to recant his testimony. Mr. Morvillo said Mr. Kumar had replied that “he testified truthfully and would do no such thing.”

Mr. Guha responded, saying: “Mr. Morvillo is wrong about his facts. Mr. Kumar called Mr. Rajaratnam’s wife first out of the blue. The relevant and troubling issue is that Mr. Kumar’s testimony at Mr. Rajaratnam’s trial cannot be reconciled with his later testimony at Mr. Rajaratnam’s brother’s trial.”

A spokeswoman for the Devens prison declined to comment on specific inmates. Mr. Rajaratnam was recently moved back to the hospital, according to those who know him.

In prison, it is Mr. Gupta’s family that has kept him going. At the camp, he pasted family photos on the bottom panel of the bunk above him. “Hey, David, look at what we have to be grateful for,” Mr. Morgan remembered Mr. Gupta saying. “‘When I go to bed, I see them, and when I wake up, I see them.’”

Until recently, Mr. Gupta’s twin granddaughters visited on Fridays. “He lights up from ear to ear when the babies come,” Mr. Morgan said. Mr. Gupta is sad they will no longer visit. Unlike the fenceless camp, visitors to the compound have to pass through clanging doors with steel bars. The Guptas decided the setting would frighten the grandchildren.

Before his recent transfer to the main compound, Mr. Gupta reported daily at 5:30 a.m. to the cafeteria, where he washed tables. He liked to take a brisk five-mile walk before the 8:40 a.m. inmate count, Mr. Morgan said.

After dinner at 4 p.m., the two walked and talked. “Those conversations were priceless,” Mr. Morgan said. “Where would I ever meet a guy like Rajat?”

The two men played handball and racquetball and were champion bridge partners.

“He is the most competitive man. Don’t let anyone tell you differently,” Mr. Morgan said. “When we played cards together, we won. Whatever he does, he played to win.”

In the summer on Thursdays, the two split a pint of ice cream from the commissary. In the winter, when the weather turned cold, Mr. Gupta started writing a book, Mr. Morgan said.

Mr. Gupta seemed to have accepted his imprisonment, telling Mr. Morgan it was his “destiny.”

Anita Raghavan is the author of “The Billionaire’s Apprentice: The Rise of the Indian-American Elite and the Fall of the Galleon Hedge Fund.”

A version of this article appears in print on , on Page B1 of the New York edition with the headline: Onetime Allies on Wall Street, Now in Prison. Order Reprints | Today’s Paper | Subscribe