After peering into a sterile prison cell, he said the nation needs to reconsider the way crime is controlled and prisoners are rehabilitated.
Obama, who has vowed to make criminal justice reform a centrepiece of his closing months in office, said he also felt a kinship with some of the young inmates.
The White House said he was the first sitting president to see the inside of a federal prison.