WASHINGTON — Ceasar Huerta Cantu did not discover the mistake until he had already spent six years behind bars. His lawyer had missed it. The judge did not notice. But studying a report he was not supposed to have, the federal inmate noticed something was wrong.

A typographical error, a single wrong digit, had consigned him to prison for an extra three and a half years that he was not supposed to serve. Once the error was discovered, the court system refused to correct it. Mr. Cantu had waited too long, a judge ruled. Only with the intervention of President Obama did it finally get fixed.

In a rare use of his clemency powers, Mr. Obama commuted Mr. Cantu’s sentence on Tuesday and spared him from being locked up for an additional 42 months. “It’s hard to imagine that someone in the federal criminal justice system could serve an extra three-plus years in prison because of a typographical error,” said Kathryn Ruemmler, the White House counsel.

The president’s action comes at a time when Mr. Obama and his administration are rethinking sentencing rules and the use of his commutation power. Over his first five years in office, Mr. Obama granted fewer acts of clemency than any modern president. But the White House and Justice Department are working on an initiative to improve the process, and that is likely to increase the number of successful petitions, especially given the sometimes-harsh mandatory sentencing.