The probability of an event is a number between 0 and 1 that expresses how likely the event is to occur. An event which cannot happen has a probability of 0, and one which is certain has a probability of 1. We often use probability in a casual way, for instance when we say “I’ll probably have to work late tonight”, but there is a mathematical theory behind it.

The most usual mathematical definition of probability is frequentist. This theory defines a probability in terms of a long series of event. We imagine doing something a great many times, and calculate probabilities based on the results. Sometimes this is easy to imagine. It is easy to imagine rolling a die many times, or flipping a coin many times. In other situations, however, this is more difficult. For example, people talk about the probability of someone winning an election, but each election is held only once. Can we even imagine holding a presidential election of Obama vs. McCain 500 times, and seeing how many times each person won?

Some of the most common uses of probability are in gambling. We assume that the coins or dice or roulette wheel or other device is fair. Then we can calculate the probability of an event as the number of times that event occurs divided by all the possible events which might occur. Sometimes this is simple. If we assume a coin is fair, then the probability of getting a head on the next toss is .5. If we have multiple events and they are independent (that is, they don’t influence each other) then we can simply multiply probabilities. The probability of getting 2 heads in two tosses is .5*.5 = .25. But things can get tricky. What is the probability of exactly 2 heads in 3 tosses? Well, when you toss a coin three times, there are 8 possibilities (not 3). The 8 are HHH, HHT, HTH, HTT, THH, THT, TTH, TTT. In 3 cases we get exactly 2 heads, so the probability is 3/8. That’s fairly straightforward to do, because there are only 8 possibilities. But what if you wanted to calculate the probability of getting 12 heads on 20 tosses? With 20 tosses, there are 2^20 possibilities! That’s over 1 million possibilities, far too many to write down. Luckily, there are formulas to help, but fully explaining them would take us too far afield.

Even with very complex problems, such as the probability of getting a particular bridge or poker hand, the basic idea is to count the ways something can happen, and divide by the total number of ways anything can happen. For instance, if you wanted to calculate the probability of getting 4 of a kind when dealing 5 cards, you would first need to figure out that there are 52*51*50*49*48 = 2,598,960 possible hands. All you need to do is figure out how many of those are 4 of a kind. We could start with how many are 4 aces: There are 48 of those, because 4 cards have to be aces, but the last card can be any of the other 48. Similar reasoning holds for the other denominations, so there are 13*48 = 624 hands with four aces. Finally, divide 624 by 2,598,960. That’s 0.00024, or about 24 out of every hundred thousand hands.

Until recently, that was the way all these probabilities were calculated. As you can imagine, this can get tricky for complicated problems. With modern computers, there’s another way: Simulation. We simply program the computer to generate many many cases of something, and then let it figure out how many are what we are interested in.