The Hobbit originally came about when Tolkien was a professor at Oxford in the 1930s. One day when Tolkien was marking student papers and came across a blank page, he unaccountably scribbled the famous opening line of the novel: "In a hole in the ground there lived a hobbit." Much later in 1955 in a letter to his former student, W.H. Auden, Tolkien writes: "On a blank leaf I scrawled: 'In a hole in the ground there lived a hobbit.' I did not and do not know why.'" (qtd. in History of the Hobbit). The idea of the character intrigued him, trying to decide who and what a Hobbit is exactly. He occasionally used his growing story to amuse his children at home, even incorporating some of the adventures into 'Father Christmas' letters he wrote for them. Two years later, the manuscript for The Hobbit was complete.
Rateliff, John D. The History of the Hobbit, Part One: Mr. Baggins. New York: Houghton Mifflin, 2007.