Had Sharafat Ali Khan been an American citizen, he likely would have been sentenced to 37 months in prison for masterminding a smuggling ring that brought more than 100 illegal immigrants from Pakistan and Afghanistan to the United States.

Instead, a federal judge in the District of Columbia sentenced Khan to only 31 months in October because he’s a deportable alien.

It’s one of the quirks of the American justice system. Because illegal immigrants and other criminal aliens usually aren’t released into halfway houses for fear they’ll abscond, they can — at least in some courtrooms — get a lesser sentence all around.

U.S. District Judge Reggie B. Walton, who sentenced Khan, said that if he’d given the human trafficker the full 37-month prison term, “the penalty that you experience is in fact be greater than the punishment U.S. citizens endure.”

Not satisfied with that leniency, Khan — who pleaded guilty — has filed a notice to the U.S. Court of Appeals for the D.C. Circuit, the very panel that set the precedent for an illegal immigrant to get a reduced sentence in a 1994 case. The appellate court ruled that a judge has the discretion to impose a reduced sentence because of immigration status.

It’s unclear how often it happens or in how many cases it would apply among the current prison population. The 1994 decision has been cited dozens of times since it was issued, but not all of the cases addressed the halfway house concern.

The appellate courts for the 2nd, 10th and 11th Circuits have ruled the other way, saying that reducing a sentence amounts to rewarding a felon for not being a citizen.

In the Atlanta-based 11th Circuit, a Burmese national, who had been convicted of selling cars with altered identification numbers, asked for a reduced sentence. He said a it would enable him to apply for asylum in the U.S., and he feared political persecution and torture in Myanmar because his father had spoken out against the government before the family fled to America.

The appeals court rejected that request.

“The effect of permitting a downward departure [reduced sentence] on these grounds would be to favor aliens with more lenient sentences than citizens of this country who commit the same crime and have the same criminal history,” Chief Judge Edward E. Carnes wrote in the 2003 case in the 11th Circuit.

Chief Judge Carnes said that, if anything, the law suggests aliens can be subject to harsher sentences than citizens.

Legal experts, however, note that judges do have a large amount of leeway, based on Supreme Court decisions on sentencing guidelines, and say Judge Walton was within his rights in reducing Khan’s sentence.

Solomon Wisenberg, a partner at the law firm Nelson Mullins Riley & Scarborough in Washington, D.C., said a judge can elect to issue a reduced sentence to a deportable alien if the felon were to face charges and punishment in his or her home country, or were to be extradited elsewhere to face trial after serving the punishment in the U.S.

Kevin McCarthy, a professor at John Jay College of Criminal Justice, said that while he agrees with Judge Walton’s reasoning for Khan’s reduced sentence, he himself wouldn’t have deleted a full six months from the criminal’s sentence.

“Where I disagree with the reasoning of this judge is his notion that an imagined punishment scale balances if one side has six months [in a] halfway house and the other side has zero additional incarceration,” Mr. McCarthy said.

“The math would have been rough, but a more logical decision would have cut the prison sentence by, say, three months to have arguable equivalency with eliminating six months in a halfway house,” he said.

The federal Bureau of Prisons has more than 35,000 non-U.S. citizens in custody.

“The vast majority of non-U.S. citizen inmates are transferred to the custody of ICE [Immigration and Customs Enforcement] upon completion of their sentence, and it is our understanding that most are subsequently deported,” said a Bureau of Prisons spokesman.

Judge Walton said he decided to cut Khan’s sentence, in part, because the pace of deportations is tricky.

The Trump administration insisted in court that Khan could be sent back to his home in Pakistan quickly. But Khan’s lawyers argued it could take a long time, forcing him to remain in ICE custody while it clears paperwork and gets official permission from Pakistan.

“I don’t know how long it’s going to take for you to be deported,” Judge Walton told Khan.

Deportable aliens are those in the country illegally or whose crimes invalidate their visitor status or green card.

Under Bureau of Prisons policy, they are not allowed to serve out the last part of their sentences in halfway houses. Sex offenders and inmates with medical issues or behavioral problems also cannot complete their sentences in halfway houses.