Why do people believe in God? For most people in the world, the answer seems obvious: Because it’s self-evident that God exists. From the point of view of the believer, the really puzzling question is how anyone could not believe.

And yet, as University of California at Irvine psychologist Brett Mercier and his colleagues point out in a recent article, there was once a time in the prehistory of our species when nobody believed in a god of any sort. Our evolutionary ancestors were all atheists, but somewhere along the way they found religion. So we’re back to our original question: Why do people believe in God?

As is common practice in evolutionary science, Mercier and his colleagues distinguish between ultimate and proximate causes. An ultimate cause explains how a behavior evolved in the first place, while a proximate cause outlines the conditions in which that evolved behavior will be performed. Consider, for example, birds flying south for the winter. The ultimate cause of bird migration is the increase in survival and reproduction experienced by those who seasonally moved to warmer climates where food was plentiful. In contrast, the proximate cause is the decrease in daylight hours, serving as a trigger that it’s time to head south.

Religious belief of some sort is a nearly universal feature of humanity, so there’s quite likely some ultimate evolutionary cause that explains it. At the same time, not all people are religious, and furthermore the forms of belief among the religious range widely, so we need to understand the proximate causes for this variation. In their article, Mercier and colleagues outline several ultimate and proximate causes for religious belief.

Fully modern humans arrived on the scene about a quarter million years ago, and until quite recently they all lived hunter-gatherer lifestyles. In these primitive societies, the men hunted, fished, or scavenged for meat, while the women gathered fruits, roots, and vegetables. They lived in small groups of around 100 to 150 people because this was the largest population that the surrounding terrain could support.

Still, these groups were considerably larger than the societies of primate species, which tend to number in the few dozen range. Furthermore, humans are far more capable of than other primates, enabled by certain evolved cognitive mechanisms. Chief among these is a sense of agency. As tool users, humans quickly developed an understanding that they can intentionally cause things to happen. The nut cracked open because I smashed it with a rock. The apple fell because I shook the tree.

Humans then apply this sense of agency to interpreting social interactions. That is to say, we not only believe we have agency, we also believe others have agency as well. Thus, we judge the actions of others depending on whether we deem them to be intentional or not. We can easily the person who accidentally steps on our foot, but we really need an explanation and an apology if someone purposely treads on our toes.

In fact, we’re rather hypersensitive about other people’s agency, inferring intention where none existed. For example, when someone cuts us off in traffic, we generally assume they did it on purpose—that is, knowing full well how dangerously they’re driving—rather than supposing they looked but just didn’t see us. We’re quick to assume that people act purposefully and discount the extent to which people’s behaviors are shaped by their current circumstances and limitations.

Because of hypersensitive agency detection, we also have a tendency to infer intentionality in natural processes or inanimate objects. Beliefs in water sprites and woodland spirits, specters and spooks, ghosts and demons, are ancient and observed in every culture around the world. Because the natural world is complex and acts in mysterious ways, we detect agency all around us.

By the way, if you think that you—an intelligent human being living in modern society—are free of such superstitious nonsense, you need to ask yourself: Have you ever begged your car to start on a cold winter morning? Or have you ever complained that your computer has a mind of its own because it doesn’t behave the way you want it to? We tend to automatically detect agency in inanimate objects whenever the situation is unpredictable and out of our control.

This kind of animistic thinking—that is, the belief that agency inhabits the world and can influence events—is a universal human trait. Such thinking is common in children, and as adults our animistic thinking is shaped by the norms of our culture. Animistic beliefs are also common in hunter-gatherer societies, but what they don’t have is organized religion.

Some 15,000 years ago, humans gradually began adopting agriculture. At first, humans domesticated a few animals and tended gardens to supplement their hunting and gathering, but eventually, all but a few societies around the world shifted solely to farming and herding. Agriculture can support many more people per acre of land compared with hunting and gathering, but this came with a cost.

As long as our group sizes were small, we had the psychological mechanisms to deal effectively with the members of our community. If you live day in and day out with the same 150 people, you get to know them really well. But if your numbers are in the thousands or tens of thousands, most of the people you interact with on a daily basis are strangers. Thus was life in the first cities that arose thanks to the food surpluses that agriculture yielded.

At this point, we see cultural evolution taking place. Human existence depends on cooperation. When we live in small groups, cheaters are punished by other members, and they quickly learn that they have to get along. But in anonymous societies, it’s easy to take advantage of others, as there’s no way for the rest of the group to punish those who take advantage of the system. The solution was to invent ever-watchful gods who’ll punish cheaters for us. Thus, organized religion grew hand-in-hand with the rise of the city-state.

Fast forward a dozen millennia, and here we are living in a technologically advanced society driven by science that tells us the world moves according to the laws of physics and not the whims of spirits or deities. Nevertheless, religious belief in one or more gods that watch over our actions and judge us accordingly is quite common. At the same time, religious belief has dropped precipitously over the last century, and here we need to look at its proximate causes.

Mercier and colleagues divide the proximate causes of religious belief into three types: cognitive, motivational, and societal. One cognitive factor is an analytical thinking style. People who tend to act according to reason rather than are also less likely to believe in God. Perhaps relatedly, we also see a tendency for people who are higher in to hold agnostic or atheistic beliefs. In contrast, people who are high in what’s commonly called “ ”—that is, the ability to easily discern the emotions and motives of others—also tend to be more religious. Of course, it’s exactly this ability to read others’ minds that led to the rise of religious belief in the first place, hundreds of thousands of years ago on the African savanna.

There are also motivational reasons for religious belief. People who are socially isolated tend to have more religious faith, perhaps allowing them to feel they’re not truly alone. Likewise, people facing death are more likely to express faith in God and an afterlife. The old saying that there are no atheists on the battlefield is no doubt true to a large extent. Furthermore, faith in God increases when situations become uncontrollable, as in the case of natural disasters. Believing that God has a plan helps people regain some sense of control, or at least of acceptance.

Another motivational factor is self-enhancement. If you live in a society where religion is prized, it’s in your best interest to say you believe, whether you truly do or not. I’m sure there are plenty of doubters in the pews at Sunday services, though none will admit it. (I was one of those for most of my teenage years.) And it’s not uncommon to hear stories of priests or pastors who’ve lost their faith but continue to preach because it’s the only way they can make a living.

Finally, there are societal factors that influence the degree of religious belief within societies. As a general rule, religious belief is considerably lower in developed countries compared with the underdeveloped world. For instance, Japan has one of the highest standards of living in the world, but only 4 percent of its population claims to be religious. Traditionally, Japan was a Buddhist country, and religion played an important role in the daily lives of the Japanese until after World War II. A similar trend has occurred in Western Europe, which many social scientists now characterize as “post-Christian.”

The United States, with its high standard of living and high , is the glaring exception. However, as Mercier and his colleagues point out, Japan and Western European have universal health care and extensive social safety nets, as opposed to the U.S. The Japanese and the Europeans know their governments will come to their aid in their hour of need. But the laissez-faire attitudes of American society make people’s futures less certain and the belief in a benevolent God more attractive.

Although many people in industrialized societies have abandoned traditional organized religion, many of them still confess to some sort of belief, such as a life-force or divine spirit that pervades nature and humanity. As societies become affluent and egalitarian, perhaps people perceive less need for a benevolent God to keep watch over us. Organized religion may no longer be needed in such societies, but it’s still human nature to perceive agency in the complexity and unpredictability of the world, even when there is none.