According to the laws of economics, people are rational.

But these laws don’t seem apply to gambling, which historians trace as far back to 3,000 B.C. Gambling has never been a rational activity, because who would invest money into something with an average negative 5% return. On average, everyone that goes into a casino with $100 will walk out with a little less than $95.

So, why do people gamble? What is the psychology, math, and economics behind Las Vegas’ favorite pastime?

Considering that people are rational, it confuses economists why people spend so much money at casinos—essentially giving away their money.

A U.S. National Library of Medicine poll asked people if they would rather have a 100% chance of $5 or an 80% chance of $6.25. While the two offers seem to be different, if played infinite times by the same players, 80% of $6.25 would average to $5. So, based on pure mathematics, players shouldn’t have a preference because these two choices are effectively equal.

However, over 75% of players stated that they would rather take the 100% chance of $5. Most economists would argue that this is due to the depressed feeling of missing out on $5, which outweighs the good feeling that might come with winning $6.25.

Interestingly, this breakdown changes with amounts. Under the same conditions, when asked if players would rather have a 100% chance of $5 or a 25% chance of $20, they were evenly split.

Also under the same conditions, when asked if they would rather have a 100% chance of $5 or a .5% chance of $1,000, about 75% of players chose a 0.5% chance of $1,000.

As the odds became higher, more players chose the gamble over the guaranteed $5. This is because we like the idea of low-risk gambling. As a species, it turns out, we prefer a small chance of winning big than receiving a smaller, guaranteed sum.

This idea of low-risk gambling can be seen in other areas of betting, too. For example, with horse racing, players would rather bet on horses that have a small chance of winning but have odds of 200/1 than bet on a horse that has a chance of winning with odds of 2/1.

A report on decision making in uncertain situations by economists Erik Snowberg and Justin Wolfers show that more often than not, the top horse has better than 2/1 odds of winning, but such rankings are deflated because people would rather bet on the underdog. Similarly, horses that have a lower chance of winning typically have lower odds than 200/1, but these odds are inflated because gamblers are willing to bet on them.

When it comes to explaining this human behavior, New York Times columnist David Leonhardt puts it best:

“People overestimate the chances of a low-probability event(s)… as is the case with plane crashes. One example I didn’t have room to mention in the magazine is what economists refer to as the “favorite-longshot bias.” It holds that gamblers tend to over-bet underdogs and under-bet favorites. For the same reason that people are afraid of dying in a plane crash although the chances are incredibly small, is the same reason people are willing to bet on the underdog despite odds not being in their favor.”

At the end of the day, it comes down to the size of potential winnings. Casinos are happy to let people gamble because their coffers are making at least 5%, and people are happy to gamble because of the potential to make serious bank.