Mr Obama said the pain that African-Americans felt around the case came from the fact that they viewed it through "a set of experiences and a history that doesn't go away".
He said African Americans were also keenly aware of racial disparities in the application of criminal laws.
"That all contributes to a sense that if a white male teen was involved in the same kind of scenario, both the outcome and the aftermath might have been different," Mr Obama said.
President Barack Obama has said that "Trayvon Martin could have been me, 35 years ago", in his first comments on the case since last week's verdict.
The unarmed black 17-year-old was shot and killed in Florida in February 2012.
George Zimmerman, 29, said he opened fire on the teenager in self-defence and was acquitted of murder by a Florida court last week.
In an unexpected press call, Mr Obama said very few black men in the US had not experienced racial profiling.
Barack Obama might be America's first black president, but it's rare for him to address the issue of race head-on like this. This was the first time he'd spoken publicly about the Trayvon Martin case since the jury found George Zimmerman not guilty of murder.
The president didn't pass comment on their decision, but said he wanted to add context to the issue of race. He said many African Americans viewed the trial through a set of history and experiences that don't go away, and that black men in particular are used to being feared, and treated differently under the law.
What was so striking was how personal he got when it came to sharing his own experiences of discrimination.
Some people have criticised Barack Obama for not being "racial" enough and this speech will certainly appease those who feel he hasn't addressed race adequately during his time in office. But there are some who will be angered the president chose to discuss the issue right now. For some, Trayvon Martin's death was not about race but about a confrontation between two men, which ended tragically.
"When Trayvon Martin was first shot, I said that this could have been my son. Another way of saying that is Trayvon Martin could have been me, 35 years ago."
He shared his experiences of being racially profiled in the past, such as being followed while out shopping.
"There are very few African-American men who haven't had the experience of walking across the street and hearing the locks click on the doors of cars.
"There are very few African-Americans who haven't had the experience of getting on an elevator and a woman clutching her purse nervously and holding her breath until she has a chance to get off," he said.
Mr Obama also hailed the "incredible grace and dignity" of Trayvon Martin's parents - Tracy Martin and Sybrina Fulton - in the way they reacted to the verdict.
Calling for "soul-searching" from Americans on issues of race, he also sounded a hopeful note, saying that race relations were improving with each generation.
Tracy Martin and Sybrina Fulton later issued a statement saying they were "deeply honoured and moved" by President Obama's comments.
"President Obama sees himself in Trayvon and identifies with him. This is a beautiful tribute to our boy," they said.
"We seek a future when a child can walk down the street and not worry that others see him as dangerous because of the colour of his skin or the clothes on his back."
Saturday's not guilty verdict for George Zimmerman from the all-female jury of six prompted nationwide protests, with further demonstrations planned for this weekend.
Mr Obama called for the protests to remain peaceful, saying any violence "dishonours what happened to Trayvon Martin".
He said that although criminal matters and law enforcement were traditionally dealt with on a state and not a federal level, it would be useful to examine some state and local laws to see if they encourage confrontation in certain situations.
On Wednesday, US Attorney General Eric Holder cited the case as he urged a nationwide review of "stand your ground" laws, such as those in place in Florida, which permit the use of deadly force if a person feels seriously threatened.
The issue was never raised during the trial, though the judge included a provision about the law in her instructions to the jury, allowing it to be considered as a legitimate defence.
Trayvon Martin was shot dead by Mr Zimmerman, a neighbourhood watchman, after an altercation in a gated community in Sanford, Florida.
Florida police did not arrest Mr Zimmerman for six weeks after the shooting, provoking mass rallies throughout the US.