As "punishment" for eavesdropping on Gandalf's conversation with Frodo regarding the dangers of the One Ring, Sam was — at his own request — made Frodo's first companion on his journey to Rivendell. They were joined by Meriadoc Brandybuck and Peregrin Took, Frodo's cousins, and journeyed together to Rivendell where the Council of Elrond took place.
When the fellowship was split up at the Falls of Rauros, Sam refused to give up his responsibilities to Frodo; he insisted on being allowed to accompany him. He carried most of the luggage, cooked, kept watch at night whenever he could, and rationed the food so Frodo had enough for the journey. It was then they encountered Gollum, who quickly became their guide. Sam never trusted the creature, and rightly, as he eventually led them to the lair of Shelob in an attempt to gain the ring after they were eaten by her. Sam was able to wound Shelob, defeating her, but not before she had stung Frodo, paralyzing and apparently killing him.
To continue the mission, Sam was forced to take the ring himself, and briefly became a Ring-Bearer. Unique among the Ring-Bearers, he was able to throw off the Ring's promise of power with barely a moment of temptation, and used its power of invisibility to rescue Frodo from the Orcs who held him captive. The two then journey alone, through many dangers, encountering Gollum again, to the eventual climax of the story and the destruction of the ring at Mount Doom.
After the hobbits' return home and the Battle of Bywater, Sam travelled the length and breadth of the Shire replanting trees that had been cut down during Saruman's brief reign of terror. He used the gift of earth given to him by the Lady Galadriel, which caused the saplings he planted to grow at an accelerated rate. The small amount remaining he took to the Three-Farthing Stone (roughly the centre of the Shire) and cast into the air, prompting the bountiful period of growth starting in the spring of the year 1420 (Shire Reckoning). The greatest wonder was a young mallorn tree sprouting in the Party Field: "the only mallorn west of the Mountains and east of the Sea" (grown from an acorn included as part of Galadriel's gift).
After the War of the Ring, Sam married Rose "Rosie" Cotton and moved to Bag End with Frodo. Sam and Rosie had thirteen children: Elanor the Fair, Frodo, Rose, Merry, Pippin, Goldilocks, Hamfast, Daisy, Primrose, Bilbo, Ruby, Robin, and Tolman.
After Sam and Rose's first child was born it was revealed that Frodo would leave Middle-earth, along with Bilbo (Sam's old hero), Gandalf and most of the remaining Elves, for the Undying Lands. Before Frodo left, he gave the estate of Bag End to Sam, as well as the Red Book of Westmarch for Sam to continue, hinting that Sam, too, might be allowed to travel into the West eventually.
After the death of his wife in the year 62 of the Fourth Age (Shire Reckoning 1482), Sam entrusted the Red Book to Elanor and left the Shire. He was not seen again in Middle-earth, but Elanor and her descendants preserved the tradition that he went to the Grey Havens and sailed into the West. As the last of the Ring-bearers, he was entitled to sail across the Sea and be reunited with Frodo in the Undying Lands.
At the start of The Lord of the Rings Sam, typically for a hobbit, had never before ventured far from the immediate area where he lived. Unusually for a hobbit, however, since childhood Sam was fond of legends and other fantastical stories. Sam was particularly interested in the Elves, and always hoped to one day see one. Sam was literate, having been taught by Bilbo and Frodo, which was atypical for most hobbits due to their rustic culture. Sam often showed a skill in poetry, one occasion being when in Lothlórien after Gandalf fell to his apparent death, Sam added to the poem that Frodo had made about him.
Tolkien called Sam the "chief hero" of the saga in one of his letters: he places special emphasis on Sam's "rustic love" for Rosie, a union that serves to establish a family in which allusions to Elvish wonders (embodied in Sam's daughter Elanor) are combined with the best qualities of traditional Shire-life. Sam and his descendants also become the keepers of the Ring-war history and uphold the memory of events that most 'ordinary' hobbits take little interest in.
The relationship between Frodo and Sam is, in many respects, at the heart of The Lord of the Rings. A strong bond of love and trust grows between them, portrayed most poignantly during the events of Cirith Ungol, where Sam vows to return to his (apparently) dead master, to be reunited with Frodo in death.
Tolkien wrote in a private letter:
"My Sam Gamgee is indeed a reflexion of the English soldier, of the privates and batmen I knew in the 1914 war, and recognised as so far superior to myself" (The Letters of J.R.R. Tolkien, ed. Humphrey Carpenter).
Frodo affectionately dubbed him "Samwise the stouthearted". The Appendix of The Return of the King says that in F.A. 7 (S.R. 1427), Sam was elected Mayor of the Shire for the first of seven consecutive seven-year terms.
"There was a curious local character, an old man who used to go about swapping gossip and weather-wisdom and such like. To amuse my children I named him Gaffer Gamgee... The choice of Gamgee was primarily directed by alliteration; but I did not invent it. It was caught out of childhood memory, as a comic word or name. It was in fact the name when I was small (in Birmingham) for 'cotton-wool'. (Hence the association of the Gamgees with the Cottons.) I knew nothing of its origin." (The Letters of J.R.R. Tolkien #257, ed. Humphrey Carpenter)
Tolkien claimed to be genuinely surprised when, in March 1956, he received a letter from one Sam Gamgee, who had heard that his name was in The Lord of the Rings but had not read the book. Tolkien replied on March 18:
"Dear Mr. Gamgee,
It was very kind of you to write. You can imagine my astonishment when I saw your signature! I can only say, for your comfort, I hope, that the 'Sam Gamgee' of my story is a most heroic character, now widely beloved by many readers, even though his origins are rustic. So that perhaps you will not be displeased at the coincidence of the name of this imaginary character of supposedly many centuries ago being the same as yours." (The Letters of J.R.R. Tolkien, ed. Humphrey Carpenter)
He sent Gamgee a signed copy of all three volumes of the book. However, the incident sparked a nagging worry in Tolkien's mind, as he recorded in his journal:
"For some time I lived in fear of receiving a letter signed 'S. Gollum'. That would have been more difficult to deal with." (Tolkien: A Biography, Humphrey Carpenter)
After publication of The Lord of the Rings, Tolkien traced the origin of the name back to Gamgee and eventually the earlier English surname 'de Gamaches'.
In the Peter Jackson movies The Lord of the Rings: The Fellowship of the Ring (2001), The Lord of the Rings: The Two Towers (2002) and The Lord of the Rings: The Return of the King (2003), Sam was played by Sean Astin. Astin's portrayal of the stout-hearted and loyal Sam is perhaps the most loyal to Tolkien's vision, although some have criticized Sam's tendency to call Frodo by his first name alone in moments of crisis.
On stage, Sam was portrayed by Peter Howe in the 3-hour long Toronto, Canada stage production of The Lord of the Rings, which opened in 2006. In the United States, Sam was portrayed by Blake Bowden in the Cincinnati productions of The Fellowship of the Ring (2001), The Two Towers (2002), and The Return of the King (2003) for Clear Stage Cincinnati. In Chicago, Dale Inghram played Sam in the Lifeline Theatre production of The Two Towers in 1999.