Religion meets many different needs for people, societies, and nations, but there are some general statements that hold true in most cases.
First, human beings cannot understand the complexity of the world around them and crave explanations for that complexity. Religion answers that need. Second, human beings seek purpose in their lives, and religion gives many people that purpose. Third, people are frightened of the responsibility of making decisions and choices, and religion imposes a structure on those decisions and choices in a way that is comforting to many. Fourth, religion provides many of us with a moral or ethical framework, rules to live a good life, and the belief in consequences for having lived properly or not.
For societies and cultures, religion can act as a glue, binding people together with common beliefs, practices, and rituals. It also tends to promote cooperation amongst the people in a culture, providing for a triumph of the whole over the individual, which is a necessity for civilized life. In fact, recent archaeological finds suggest to anthropologists and sociologists that "civilization" did not truly begin until man "found" religion, that it was religion that prompted the building of societies.
Religion is a nation-building mechanism in history, even an empire-building mechanism, for example, the Holy Roman Empire, or most of Europe before Protestantism. To some degree, the Ottoman Empire is an example, too. Again, religion acts as a glue that can hold a nation or empire together. Today, we are seeing played out in some Arabic countries the dynamic of religion in nation-building. Will some of the newly democratic nations build on religion as their legal and national framework? In the United States today, there is a trend to want to characterize the United States as a Christian country, which is a problem because of the First Amendment to the Constitution, which prohibits the United States from being a nation with a religious framework. This creates tensions within our nation, making religion, in this case, a very ineffective sort of glue.
Of course, I want to emphasize that these are very general statements, since religion is as varied as mankind, and as complex.