The Lord of the Rings in conception was meant as a sequel The Hobbit, his tale for children published in 1937. The popularity of The Hobbit led to demands from his publishers for more stories about Hobbits and goblins, and so that same year Tolkien began writing what would become The Lord of the Rings - not to be finished until 12 years later in 1949, not be fully published until 1955, by which time Tolkien would be 63 years old.
[...]
Persuaded by his publishers, he started 'a new Hobbit' in the third week of December 1937. After several false starts, the story of the One Ring soon emerged, and the book mutated from being a sequel to The Hobbit, to being, in theme, more a sequel to the unpublished Silmarillion. The idea of the first chapter (A Long-expected Party) arrived fully-formed, although the reasons behind Bilbo's disappearance, the significance of the Ring, and the title The Lord of the Rings did not arrive until the spring of 1938. Originally, he planned to write another story in which Bilbo had used up all his treasure and was looking for another adventure to gain more; however, he remembered the ring and its powers and decided to write about it instead. He began with Bilbo as the main character but decided that the story was too serious to use the fun-loving hobbit and so Tolkien looked to use a member of Bilbo's family. He thought about using Bilbo's son, but this generated some difficult questions, such as the whereabouts of his wife and whether he would let his son go into danger. Thus he looked for an alternate character to carry the ring. In Greek legend, it was a hero's nephew that gained the item of power, and so the hobbit Frodo came into existence.
"As the high Legends of the beginning are supposed to look at things through Elvish minds, so the middle tale of the Hobbit takes a virtually human point of view - and the last tale [The Lord of the Rings] blends them."
—Tolkien on The Silmarillion, The Hobbit, and The Lord of the Rings respectively
Writing was slow due to Tolkien's perfectionism and a wartime shortage of paper. It was frequently interrupted by his obligations as an examiner, and other academic duties.