US President Barack Obama has sent a letter to Congress blaming the politicians for his failure to close the military prison at Guantanamo Bay, Cuba.

Obama leaves office with 41 detainees remaining at the facility used to detain terrorist suspects in 2002 as the George W Bush administration grappled with the fallout of the September 11, 2001, terrorist attacks and the start of the US war in Afghanistan.

Obama had pledged to shutter the facility, ordering its closure just days after taking office in 2009.

His administration however has run up against frequent road blocks, including public opposition, difficulty in finding third countries to accept detainees and legal prohibitions put in place by Congress.

The Obama administration transferred 196 detainees.

"History will cast a harsh judgement on this aspect of our fight against terrorism and those of us who fail to bring it to a responsible end," Obama wrote in the letter to Speaker of the House Paul Ryan.

"Guantanamo is contrary to our values and undermines our standing in the world, and it is long past time to end this chapter in our history."

Obama leaves office Friday after eight years as Donald Trump is sworn in as president.