The judge who sentenced Raymond Surratt Jr. to life in prison didn’t think he deserved that tough a penalty. His attorneys said it was based on bad math. Even the government lawyers who prosecuted him say the sentence was a mistake.

Yet they all also agree Surratt might stay locked up forever.

How that came to be is at the heart of arguments to be heard Wednesday when the U.S. Court of Appeals for the 4th Circuit takes up Surratt’s case, which turns on how many times inmates can appeal a sentence, particularly if the law becomes more lenient after they are sent to prison.

“Raymond Surratt will die in prison because of a sentence that the government and the district court agree is undeserved and unjust,” a judge wrote last summer, siding with Surratt in a divided panel decision from the same court.

The judges who ruled against him in the 2-to-1 decision are also sympathetic. They just don’t think the courts have the power to do anything about it.

Raymond Surratt Jr. (Family photo)

If Surratt were resentenced today, he would face a mandatory minimum penalty of 10 years in prison, likely making him eligible for immediate release. The North Carolina man is being held at a federal facility in western Virginia, near the border with Kentucky, after a 2005 cocaine conviction.

Courts throughout the country routinely revisit and revise past convictions and sentencing errors. But Surratt’s case underscores the limits of those reviews and poses the question of how the legal system should balance finality with evolving notions of fairness.

Surratt’s case comes as advocates for criminal justice reform, including President Obama and lawmakers on Capitol Hill, are working to roll back decades of prison sentences, set down during the nation’s war on drugs, that they see as excessively harsh.

The president is expected to use his clemency powers to commute the sentences of a group of nonviolent drug offenders in the coming weeks, but there are still thousands of pending applications for early release.

Until the Surratt case, no federal appellate court has considered whether it has a way to fix a mistake of its own making when the error is as severe as a mandatory life sentence.

“The issues in this case are basic to the fairness of federal criminal justice,” the government said in its brief on behalf of 41-year-old Surratt.

If the court’s initial panel ruling against Surratt stands, the government says, the court will be shutting down the possibility of “relief for even those serving the longest sentences, based on the plainest of legal errors.”

In a sign of the importance and complexity of the issue, the government’s case is being argued before the full court in Richmond by a top deputy from the U.S. solicitor general’s office, Michael R. Dreeben.

With prosecutors and defense lawyers in the unusual position of being allied for Surratt, the appeals court panel appointed a Georgetown University law professor to argue the other side. The panel ended up agreeing with him in July.

Steven H. Goldblatt, who runs Georgetown’s appellate litigation program, and the majority say that there is value in finality in the legal system and that Congress has given federal prisoners another shot at challenging their sentences only in the narrowest of circumstances.

“Although one might find it tempting to put finality concerns aside for the sake of self-designed notions of fairness,” the majority said, it provides “closure to victims and the defendant: it assures the victim that his assailant will be punished, while it directs the defendant to move on with his life.”

When Surratt pleaded guilty to conspiring to distribute at least 50 grams of cocaine in western North Carolina, he was 31 and one of 19 members of a large drug ring. Surratt had been caught three other times on lesser cocaine-related charges.

As part of his plea deal, Surratt waived his right to appeal and acknowledged that he faced the possibility of a mandatory life sentence if he did not fully cooperate with the government.

At sentencing, prosecutors said Surratt’s cooperation efforts were “halfhearted” and had not furthered their investigation. Even though sentencing guidelines recommended a maximum penalty of about 20 years, the judge said he had no choice but to impose a mandatory life sentence because of Surratt’s earlier drug convictions. He called the penalty “undeserved and unjust.”

The conviction and sentence were upheld after Surratt’s initial appeals.

Six years later in 2011, judges for the 4th Circuit, which includes North Carolina, issued a decision that overruled past practice. The ruling corrected the court’s understanding of how defendants’ previous state-level convictions in North Carolina should be factored into a judge’s calculations for determining the length of prison terms.

For Surratt, the new interpretation meant that his prior convictions should not have triggered a mandatory life term.

Surratt has asked for one last chance to be resentenced under the new rules. The government says he should get it, arguing that courts should be allowed to reconsider cases — even when a prisoner has exhausted his initial appeals — when it comes to fixing “fundamental defects” or errors.

In its decision last summer, the panel majority said it was “not unsympathetic to his claim.”

Allowing Surratt to challenge his sentence, however, would “thwart almost every one of the careful limits that Congress placed on post-conviction challenges to a federal prisoner’s sentence,” according to the majority opinion written by Judge G. Steven Agee, who was joined by Chief Judge William B. Traxler Jr.

Congress has long tried to rein in endless legal reviews of convictions. In 1996, a Republican-controlled Congress, with the support of President Bill Clinton, enacted new limits on challenges from federal inmates.

Prisoners can try to reopen their cases only in rare situations, such as when new evidence is discovered or when a change in law means the offense in question is no longer a crime.

Surratt’s case, according to the panel majority, is not the type of exception Congress envisioned: He is not innocent, and his sentence did not exceed the maximum penalty set for his offense by Congress.

In his strongly worded dissent last summer, Judge Roger L. Gregory responded that the only punishment more severe than a life sentence would have been death.

“What a perverse result, to have suffered a fundamental sentencing defect, and then to be punished for not having received the death penalty,” Gregory wrote.

If the court sides with Surratt, the panel majority said, the statute would become “a catchall” for prisoner challenges for “perceived errors big and small.”

Besides, the majority said, Surratt is not without other options. Congress could amend habeas corpus law to allow for cases such as this one. The government, which is already arguing on Surratt’s behalf, could also help him seek clemency from the president.

Obama has commuted the sentences of close to 200 federal inmates, including 95 prisoners in December. An additional 9,115 petitions for early release are still pending. The last pardon attorney resigned in January, frustrated with the process and a lack of resources to handle the crush of applications.

“It is within our power to do more than simply leave Surratt to the mercy of the executive branch,” Gregory wrote. “To hope for the right outcome in another’s hands perhaps is noble. But only when we actually do the right thing can we be just.”

Sari Horwitz contributed to this report.