Most people know that your chances of winning the lottery are astronomically small. Yet this is only half the reason why you should invest elsewhere. The other half is the amount of money you have to pay to receive those poor odds. With that info, you can use a simple calculation to determine whether a bet is worth it or not.

In any chance situation (known formally as a random variable) you can calculate the “expected value”. This is a number representing the value you can expect to win (or lose) for each time you play a game of chance. You find it by multiplying the result of each outcome by the chance of that outcome occurring, and then adding all of them together.

If you bet someone a dollar that a coin will come up heads, there are two possible outcomes. Either you lose a dollar (if it is tails), or you gain a dollar (heads). Each of these options is equally likely, and we express the probability as a number from 0 to 1 (instead of a percentage):

-1: .5

+1: .5

The expected value is 0 dollars (-1 * .5 + 1 * .5 = 0). Note that no single coin toss will result in you losing 0 dollars, you always either lose 1 or gain 1. The expectation tells us what we will average if we play the game a large number of times. In fact, the more times we play, the closer the average will come to 0 (this is called the law of large numbers).

Consider how it changes if you would receive 2 dollars on heads, but still only lose 1 on tails.

-1: .5

+2: .5

(-1*.5) + (2*.5) = .5.

Now, for every game you play, you should expect to win $.50.

This law of expectation is used by casinos to make sure that the odds are just slightly in their favor. That is, every casino game has an expected value of slightly less than 0 (from your perspective), so over time they will make money. A roulette wheel has 38 slots. 18 of them are red, 18 black, and two are neither. The odds of red winning are 18/38 = .474, and the odds of red losing are 20/38 = .526. When betting red, you can expect to lose 52% of the time and win 48%. The casino knows this, and sets the payout at 2 to 1.

If you bet 100 dollars:

+$100: .474

-$100: .526

The expected value of each $100 spin is $-5 . So if you spin a hundred times, you will win a few times, but you can expect to be about $500 in the hole when you’re done. It’s not luck that makes the house always win, it’s math. Thanks to the uncertain nature of probability, there are people who walk away from an evening of roulette gambling in the black (in fact, it would be strange if this weren’t the case, but I’ll save that for another post). But if you consider every person who played roulette that evening, the casino made about $5 per bet placed (assuming all the bets were on red for $100).

Back to the lottery, the game is played by selecting 5 numbers from 1-59 and one ball from 1-35 from a new pool of numbers. The odds of selecting the correct combination are:

1 / (59*58*57*56*55*35) = 1 / 21,026,821,200

21,026,821,199 outcomes result in you losing your ticket price (let’s say it is $5), and you win the jackpot on the other 1 outcome. For this example, let’s assume the jackpot is 500 million. (There are other winning tickets that pay out less, but we’ll ignore them for the sake of a simple example, it doesn’t change the outcome much).

-5 * (21026821199 / 21026821200) = -4.9999999997

500,000,000 * (1 / 21026821200)= .025

On a 5 dollar lottery ticket with a jackpot of half a billion dollars, you should expect to lose $4.974 for each time you play. If you could play the lottery a trillion times, you would probably have a few winning tickets, but your winnings minus total cost of lottery tickets divided by number of times you’d played would be about $-5 trillion.

If you somehow noticed that a particular roulette wheel happened to land on one number more often then others, that would change the expected value to positive, and you could play that wheel with confidence (usually the odds of a single number coming up are 1 in 38, but if it were just a little better, 1 in 33, the expected value of each spin would become +11). This is almost exactly what Joseph Jagger did in 1873, and he ended up winning the equivalent of 700,000 pounds at the Monte Carlo in Monaco by betting on 9 numbers that occurred more than the others.

In 1992 a group of investors in Australia noticed that the Virginia lottery had a positive expectation. They had a chance of winning about 28 million dollars, but the odds were 1 in 7 million of winning. So, they bought a large number of lottery tickets, and ended up cashing in. They had to front a large sum of money to buy enough tickets, but for each ticket they bought they expected to win money, so in this rare case, there was no reason not to play.

A solid understanding of probability will help you avoid games of chance in which you will lose, and take advantage of those in which, over time, you will win.