Retiring state and municipal workers padding their pensions with overtime could cost New York taxpayers $32 billion to $54 billion over the next 20 years, according to a new study.

In a report out Monday, the Center for Cost Effective Government crunched the numbers to project the fiscal reverberations of public servants piling up overtime in the waning years of their careers.

“These obligations are a time bomb waiting to explode,” said executive director Steve Levy.

Because the size of a retiring worker’s pension is typically derived from their three highest-paying years — generally the last three of their career — it’s common for senior employees to inflate the rate by going out with a deluge of overtime, he said.

“The six-figure pension — which used to be an anomaly — is now the norm for those retiring from certain unions,” said Levy, a former Suffolk County executive.

Projected to be among the biggest burdens on taxpayers over the next two decades are the MTA, correction officers and the NYPD — where departing workers’ OT is expected to add another $5.69 billion, $3.15 billion and $2.65 billion, respectively, to pension costs.

But the largest share belongs to workers under the New York State Employee Retirement System, which includes everyone from state park rangers to State University of New York professors, according to the review.

All told, NYSERS members are expected to have their pensions inflated by OT to the tune of $14.12 billion over the next 20 years.

That’s nearly half of the $32.91 billion that Levy says is a conservative estimate for the sum.

But the actual impact could be closer to $54.48 billion, according to Levy — and neither figure accounts for inflation.

Though cases of alleged pension fraud do factor in, the biggest drains are perfectly legal, he noted.

“It’s not the illegal overtime that is primarily the problem,” said Levy. “It’s the overtime garnered legally via outrageous contractual provisions and convoluted work rules.”

For public workers hired after April 2012, the amount of OT that can count toward a pension is capped at 15 percent of their base salary, thanks to a state law passed in 2010.

But Levy said those savings are likely to amount to too little, too late, and called on Albany to pass legislation stopping OT from factoring into pensions entirely.

John Samuelsen, president of the Transport Workers Union — whose members include MTA workers — said cuts to his constituents’ pensions were a non-starter.

“The retirement security of working people is constantly under attack, and ironically in this instance by a rich suburban lawyer who was chased out of public service for ethics violations,” said Samuelsen of Levy, who in 2011 agreed not to seek re-election amid a probe into alleged fundraising misuse.

“He should give up his own public sector pension before he tries to target ours,” added Samuelsen.

Levy, who was never charged with a crime and said that his $70,000 pension is not inflated by “a dime in overtime,” added that without belt-tightening, no one will be able to benefit from pensions.

“The point is I want the pensions to be there for everyone,” he said. “If the pension system collapses, everyone will take a haircut.”