Bernie Madoff had little to lose by confessing to masterminding the world’s biggest Ponzi scheme — he’s dying of cancer, sources told The Post.

Madoff, who is serving 150 years at a North Carolina federal lockup after pleading guilty to swindling more than $65 billion, has been telling fellow inmates he does not have much longer to live.

“He’s been taking about 20 pills a day for his cancer,” said one inmate.

“He talks about it all the time. He’s not doing very well.”

There’s been much speculation as to why Madoff took the entire fall for the scheme — and rumors of his suffering from pancreatic cancer surfaced many months before he arrived at the Butner, NC, complex in June.

The prisoners did not confirm that’s the form of cancer he’s suffering.

His lawyer did not return messages yesterday but, when previously asked by The Post, would neither confirm nor deny his client has cancer. A lawyer for his wife, Ruth, also did not return messages.

Meanwhile, a bare-chested Bernie has been killing time at the prison participating in Native American religious purification ceremonies held at an on-grounds “sweat lodge,” other sources said.

He accepted invitations from Native American inmates to join them at their weekly prayer services. The ceremonies involve praying, using heated rocks to induce sweat and smoking from a ceremonial pipe.

It is unclear whether the 71-year-old Madoff checked out the ceremony because of health reasons. For centuries, Native Americans have used sweat lodges to help detoxify the body mentally, spiritually and physically.

Inmates who participate are usually shirtless, and Madoff was no exception earlier this month during the first ceremony he attended, according to the prisoners.

Madoff is also making new friends at the prison complex through another unlikely clique — the homosexual posse, although the relationships are purely platonic, according to the sources.

“In prison, you stick to your own kind, but he’s doing the exact opposite by hanging with the Indians and [homosexuals] — so who is going to have his back?” wondered one jailbird.

Another inmate said various “gangs” at the prison are trying to recruit Bernie to their crews.

Some prisoners are also bending over backward trying to satisfy his hearty appetite by regularly cooking sandwich wraps for him back at their cells.

“They’re trying to kiss his butt,” said one source.

Madoff was quickly assigned a job in the prison’s engraving section when he first arrived, but last month he was transferred to a job painting fences.

rich.calder@nypost.com