Barack Obama will return 5% of his salary to the US treasury in a show of solidarity with federal workers affected by $85bn in government-wide spending cuts.

Hundreds of thousands of workers could be forced to take unpaid leave if Congress fails to reach an agreement soon to undo the cuts, which came as punishment for the inability of the Obama administration and Congress to come up with another way to address the country's debt.

The 5% that Obama will hand back mirrors the 5% cut that domestic agencies took when the reductions went into effect. The Pentagon's budget took an 8% hit.

Every federal agency is grappling with spending cuts, which the White House has said could affect everything from commercial flights to classrooms.

A 5% cut from the president's salary of $400,000 (£265,000) a year amounts to $20,000.

"The salary for the president, as with members of Congress, is set by law and cannot be changed," Obama's spokesman, Jay Carney, said on Wednesday. "However, the president has decided to share in the sacrifice being made by public servants across the federal government."

A day earlier the defence secretary, Chuck Hagel, committed to taking a salary cut equal to 14 days' pay – the same level of cut that other defence department civilians are being forced to take.

Obama is not the first president to give up part of his salary. John F Kennedy donated his presidential salary to various charities, according to Stacey Chandler, an archivist at the John F Kennedy Presidential Library. George Washington, the first president, tried to refuse a presidential salary, but Congress required that the position pay $25,000.

As Obama's salary is set by law, he must accept the funds and then write a cheque to the treasury each month for the portion he plans to give up. Obama's decision, first reported by the New York Times, will not affect the other perks afforded the president, from a mansion staffed with servants to the limousines, helicopters and Boeing 747 jumbo jet.