One of the most difficult things for foreigners to do properly is bow or ojigi (お辞儀). Why do people bow in the first place? Bowing is a customary sign of respect. How one bows and how low they bow depends on the situation and ones sincerity. The hardest part is knowing what type of bow is necessary for the situation. It is said that no two people are of the same rank. Therefore, one should always assume that the other person is of higher status and thus treat them with more respect. This idea of rank and respect is a difficult one for even native Japanese people. For instance in 2009, President Obama was criticized for bowing to the Emperor of Japan. The proper form for bowing to someone of the Emperors stature is called Saikeirei (最敬礼) and one bows to a 45 degree angle with their back straight. Many said that his bow was too deep and that he let his back curve and his head drop. Others said he was the leader of free world and thus not obliged to bow to someone who is not even a true head of state.
Here is how I read the situation. For starters, President Obama was in Japan and thus must follow the etiquette of the land he is visiting. Two, the Emperor of Japan holds a hereditary rank and President Obama holds a positional rank. So technically speaking, regardless of one's politics, the Emperor is of higher rank. Next, President Obama is six feet one inches tall and the Emperor is five feet five inches tall so it was necessary for him to drop his head below that of the Emperors (In samurai culture his head could never be held higher than the Emperors). Finally, President Obama's bow was neither naive or offensive. He is a foreigner who was trying to conform to the local custom and the Emperor, who is schooled in every detail and nuance of etiquette, would have realized Obama's sincerity. There is a saying, "In terms of respect, never be outdone." President Obama was showing the Emperor respect by bowing the way he did despite the fact he is a foreigner. The Emperor showed Obama respect by realizing the nuances of the situation and not getting offended.
Below I have posted a pretty good basic outline for bowing.