There is a way to read The Hobbit as an allegory for the belief system at the core of Christianity. Tolkien, a devout Catholic, insisted that his books were not direct Christian allegories. In fact, he famously disliked the way his friend C.S. Lewis used his own fantasy world, Narnia, to promote Christian teachings. Tolkien aspired to create a fantasy world that was not a reflection of the real world or its ideologies, but rather a world all unto itself. The people of Middle Earth have no concept of Christianity as an institution and hardly even have any organized religion. However, there is some tension between Tolkien’s criticism of Lewis and the many, many parallels between The Hobbit and the Bible.
For example, Smaug has a great deal in common with Satan. Both are snake-like, both are master manipulators, both bring fire and destruction wherever they go, and both drive people out of their original home and away from their birthright. Similarly, Thorin has a great deal in common with Christ. Just as Jesus is the son of God, Thorin is descended from the once-great King under the Mountain. He leads his people back to their birthright (the treasure in the mountain as opposed to immortal Paradise in the Garden of Eden) and, like Jesus, dies so that they might once more have access to it. He does not have a grand moment of resurrection, but he nonetheless becomes a Christlike figure of salvation. Bilbo, on the other hand, is repeatedly assumed dead only to show up once more to save the day. In this way, he too resembles Christ.
Tolkien's biblical echoes can be attributed in part to his deep and abiding interest in the Middle Ages. European art, literature, and even historical and scientific writings from this period were heavily influenced by Christianity. Even when Tolkien draws on source material like Arthurian legend, the source material is inflected with Christian ideas. However, it is also important to consider Tolkien's framing of the novel as a translation of historical records from a far-off land. He presents Middle Earth as a world that has developed with no interference from the "real" world, its institutions, or its ideology. The biblical elements of the novel demonstrate that even without the influence of Christianity, the people of Middle Earth believe in the triumph of good over evil. They struggle with temptation and wonder how much they are willing to sacrifice for others. They hope for salvation and rally around the heroes who show up to fight for them. Many of Christianity's most central ideas, Tolkien seems to argue, have staying power that extends far beyond the religion itself: left to its own devices, any culture will develop its own version of a belief system that emphasizes similar values.
Tolkien was reluctant to admit that his fantasy directly represented real-world events, but The Hobbit can be interpreted as an allegory for World War I (a horrifyingly violent war in which Tolkien fought). Thorin lays the groundwork for the allegory in Chapter 1, when he describes Smaug's initial pillaging of the Lonely Mountain:
So my grandfather’s halls became full of armour and jewels and carvings and cups, and the toy market of Dale was the wonder of the North.
Undoubtedly that was what brought the dragon. Dragons steal gold and jewels, you know, from men and elves and dwarves, wherever they can find them; and they guard their plunder as long as they live (which is practically for ever, unless they are killed), and never enjoy a brass ring of it.
World War I is one of the more difficult-to-understand conflicts in history because it had many layered causes. Rather than an escalated conflict between two distinct countries, it resulted from decades of building tension in Europe. This tension largely stemmed from industrialization and imperialism. Rich countries raced to build wealth for wealth's sake through technological advancement and through the expansion of their borders. The rich tended to get richer, while the poor were exploited. Entire countries were colonized by expanding empires. Thorin describes Smaug, and dragons more generally, as being like these empires: they are all greedy plunderers with no appreciation or respect for the cultures and people they exploit.
The last several chapter of the book unfold much like World War I. In the real-world event Tolkien lived through, a political assassination ignited a war between Austria-Hungary and Serbia. The assassination was meant to deal with a local territorial dispute. Before long, though, due to the various alliances and tensions throughout Europe at the time, Belgium, Germany, France, Russia, the U.K., the declining Ottoman Empire, Italy, Bulgaria, Romania, and Greece all joined in. Over the course of more than four years, all of these countries worked out their relationships to one another on bloody battlefields that extended even beyond Europe, to territory occupied by European powers in Africa and the Middle East. The war ended with a tentative peace and re-commitment to diplomacy that eventually devolved once more into World War II.
In Tolkien's novel, it only takes the first 11 of 19 chapters for Thorin and his company to find the side entrance to the Lonely Mountain, which has been their primary goal all along. By the end of Chapter 14, Smaug has been defeated. Logically, the book should be over. As with World War I, however, one people's struggle against their enemy turns out to be bound up with a whole array of other conflicts. Not only the dwarves, but also the men and elves believe that they have a claim to the Lonely Mountain and its treasure. The goblins and Wargs want the treasure too, and they want revenge on Thorin's party. The elves, men, eagles, and even Beorn are united with the dwarves against these enemies, even though they are close to war with the dwarves over the mountain. The rest of the book is taken up by the battle of Five Armies and the diplomatic division of treasure and territory. Tolkien leaves the reader with the uneasy sense that wars are never as quickly resolved as they are begun.