Samurai committed seppuku for a number of reasons, in accordance with bushido, the samurai code of conduct. Motivations could include personal shame due to cowardice in battle, shame over a dishonest act, or loss of sponsorship from a daimyo. Often times samurai who were defeated but not killed in battle would be allowed to commit suicide in order to regain their honor.
Sometimes, particularly during the Tokugawa shogunate, seppuku was used as a judicial punishment. Daimyo could order their samurai to commit suicide for real or perceived infractions. Likewise, the shogun could demand that a daimyo commit seppuku.
Battlefield seppukus were usually quick affairs; the dishonored or defeated samurai would simply use his short sword or dagger to disembowel himself, and then a second (kaishakunin) would decapitate him.
Planned seppukus, on the other hand, were elaborate rituals. The samurai ate a last meal, bathed, dressed himself carefully, and seated himself on his death cloth. There, he wrote a death poem. Finally, he would open the top of his kimono, pick up the dagger, and stab himself in the abdomen.
The more common form of seppuku was simply a single horizontal cut. Once the cut was made, the second would decapitate the suicide. A more painful version, called jumonji giri, involved both a horizontal and vertical cut. The performer of jumonji giri then waited stoically to bleed to death, rather than being dispatched by a second.
The word "seppuku" comes from the words setsu, meaning "to cut," and fuku meaning "abdomen."