Every now and then I like to play a game of poker.
Hands, in poker, are ranked according to the basic chances of them occurring. Those hands that would randomly occur with a lower frequency rank higher than those that are more likely to occur. In the most vanilla form of poker, five cards are dealt to make a hand. The hand rankings for five card poker are shown in the table below.
A standard deck of playing cards contains 52 cards, and these can be arranged to make a total of 2,598,960 distinct sets of five cards. Mathematicians often write this number as _{52}C_{5} (spoken as “52 choose 5”). It's a measure of the ways that five cards can be selected from 52 cards without replacement, and not worrying about their order. 
The calculation of these choices (also called combinations) are the number of ways that k items can be picked from a set of n items in an unordered way. It can be calculated using the following formula:

If five cards are dealt, to the left is the table of all the ranks and the frequencies of them occuring. The highest ranked hand is the straight flush. In a straight flush, all cards are of the same suit (flush), and they are numerically connected in order (straight). If there is more than one straight flush, the value of the highest card is compared. Many poker enthusiasts call out the very highest possible Straight Flush: AKQJ10 and give it the special name of a Royal Flush, but there is no real reason to do this as it's simply a higher version of a regular straight flush. Even though there are 40 possible straight flushes, there are only four possible royal flushes. One for each suit. 
It's a fun exercise to see how we can mathematically derive all the above frequency numbers.
Straight Flush 
For a straight flush, not only do the cards need to be of the same suit, but they all need to be numerically connected. There is only one of each card of each suit. The highest possible straight flush ends with an Ace. The next highest ends with a King, then a Queen, all the way down to the run ending with a five. In poker the Ace can be used either as a highcard, or a lowcard (but not both types in the same hand, so it's not possible for a straight to roll over the top).
This means there are ten possible straight flushes in any suit: AKQJ10, KQJ109, QJ1098 … 5432A
(The lowest straight is also given the vernacular name of a Wheel).
Ten possible straights in each suit, and four suits, results in 40 possible straight flushes out of the 2,598,960 hands.
Another way to calculate this is to say we have _{10}C_{1} × _{4}C_{1} (Ten possible choices for the first card, and four possible suits).
Four of a kind 
To get four of a kind we have, as the name implies, four of one kind, then a singleton. As there are only four of any number, this singleton can by any of the other nonused cards.
There are thirteen different cards that can be used for the quads: A,K,Q,J,T … 3,2, this leaves 48 other cards for the singleton. So the number of possible hands is 13 × 48 = 624.
Another way to calculate this is to say we have _{13}C_{1} × _{48}C_{1} (Thirteen possible choices for the quads card, and fortyeight possible choices for the singleton).
Full House 
In a full house, there are three of one kind of card, and two of another. There are thirteen possible cards that can be used for the triple, leaving twelve possible (different) cards that can be used for the pair. For the triple, as there are three cards, there are _{4}C_{3} different combinations of the cards (An easy way to think of this is that this has to be four: If you are selecting three cards, there are four ways, one for each suit that is missing).
After the triple, there are twelve possible cards that can be selected as the pair.
There _{4}C_{2} ways the suits of the twelve possible pairs can be arranged.
So the number of full houses possible is: _{13}C_{1} × _{4}C_{3} × _{12}C_{1} × _{4}C_{2} = 13 × 4 × 12 × 6 = 3,744.
Flush 
This one gets a little more complicated, but there's a little trick, and we can leverage a previously calculated answer.
For a flush, all the cards are the same suit. Let's pick the suit first. There are _{4}C_{1} choices.
There are 13 cards in a suit, and from these, we need to pick any 5, so this would have been _{13}C_{5}, however if we do this we'll be double counting a straight flush (where all the cards are in numeric order). We have, however, already determined there are forty straight flushes, so all we have to do is subtract this number of straight flushes from all the flushes.
Flushes: (_{4}C_{1} × _{13}C_{5}) − 40 = (4 × 1,287)  40 = 5,108.
Straight 
The calculations for a vanilla straight is a little more complex.
As from above there are ten possible cards that the highest card of the straight can be. This card can be any one of the four possible suits, so as a starting point there are 10 × _{4}C_{1} = 40 possible top cards of any straight.
After this card, the numeric value of each subsequent card below is already defined; the only variable is suit, and there are _{4}C_{1} ways each next card can be selected. The last step, as above, is to subtract out the number of straight flushes, to stop the double count if all the cards in the straight have the same suit.
Straight: ((10 × _{4}C_{1}) × _{4}C_{1} × _{4}C_{1} × _{4}C_{1} × _{4}C_{1})  40 = 10 × (_{4}C_{1})^{5}  40 = (10 × 1,024)  40 = 10,200.
Three of a kind 
Things are getting a little more complex. For three of a kind, we can have any of the thirteen possible numbers for the triple (just like the start of the full house), but for the two remaining cards, not only do they need to be different from the triple, they need to be different from each other (otherwise they set would be a full house). We don't care what the suit of these last two cards are, so there are _{4}C_{1} ways for each of these singletons.
Three of a kind: _{13}C_{1} × _{4}C_{3} × _{12}C_{2} × (_{4}C_{1})^{2} = 13 × 4 × 66 × 16 = 54,912.
Two Pairs 
For two pairs there are thirteen possible values that each of the pairs could have, and from these we need to select two _{13}C_{2}. Each of these pairs can be made from two differenent suits _{4}C_{2}. The singleton can have a value of any of the other unused 11 cards _{11}C_{1}, and be any one of the suits _{4}C_{1}
Two Pair: _{13}C_{2} × (_{4}C_{2})^{2} × _{11}C_{1} × _{4}C_{1} = 78 × 36 × 11 × 4 = 123,552.
Pair 
To get a hand with a pair there are thirteen possible values for the paired card _{13}C_{1}, and this can happen in _{4}C_{2} suited ways. The remaining three cards can be any suit, and we need to select this card from the remaining 12, so _{12}C_{3} cards each one of them _{4}C_{1} suits.
Pair: _{13}C_{1} × _{4}C_{2} × _{12}C_{2} × (_{4}C_{1})^{3} = 13 × 6 × 220 × 64 = 1,098,240.
High Card 
In theory, we don't need to calculate this value. Paraphrasing Sherlock Holmes; once we've eliminated the impossible, whatever left is the solution. We know the total number of possible sets is 2,598,960 and we've calculated the occurences of all the other possible hand rankings. If we add up all the other ranking hands and subtract this from the total number, we should be left with the number of hands which have nothing but a high card.
However, since we like the challenge (plus it's good verify), here's the calculation.
Because the values of the card have to be distinct (not even a pair), there are _{13}C_{5} basic ways these values can be selected. Let's assume, for now, that each of these cards can be any suit.
We're almost home. From this value we subtract away the number of straights, flushes, and straight flushes.
High card: _{13}C_{5} × (_{4}C_{1})^{5}  40  5,108  10,200 = (1,287 × 1,024)  40  5,108  10,200 = 1,302,540.
Another way to calculate this value is to start with the _{13}C_{5} ways to get five values and from that subtract the 10 we know are the only straights. This gives us the values of the cards. Then we need to look at the suits. Each of the cards can be any the suits, with the exception of the four times when the suits all align and it would be a flush.
Alternative High card calculation (_{13}C_{5}  10) × ((_{4}C_{1})^{5}  4) = (1,287  10) × (1,024  4) = 1,302,540.
Thankfully all our possible hand combinations add up to 2,598,960. Phew!
A standard deck of cards has four suits. Because of this, a full house occurs less frequently than a flush, which inturn occurs less frequently than a straight. What would happen if there were less suits in a deck, or more suits?
This is an interesting thought exercise. If we had a 'skinny' deck with just three suits (or maybe even two?), then flushes would become much more common. Taken to the limit, if there was just one suit, then every hand would be a flush!* How would the other probabilities change?
An added complication is that, with more than five suits it is possible to get a new hand type: Five of a Kind!
*Or a straight flush!
Going the other way, what if cards could have more than 13 different values? The higher the number of cards in a deck, the harder it would be to make straights. If we say that Jack=11, Queen=12, and King=13 how would the probabilities change if there were 15 distinct cards for each of the four suits? How about 20? How about if we combined both these and varied both the number of suits and the range of the cards? 
Leveraging what we've learned above it's possible to derive generic formulae for the number of occurences of each of these hands.
If S is the number of suits in a deck, and V is the range of values, then here are the generic formulae for the number of hands:*
Five of a kind  _{V}C_{1} × _{S}C_{5} 
Straight Flush  _{V3}C_{1} × _{S}C_{1} 
Four of a kind  _{V}C_{1} × _{S}C_{4} × _{VSS}C_{1} 
Full House  _{V}C_{1} × _{S}C_{3} × _{V1}C_{1} × _{S}C_{2} 
Flush  (_{V}C_{5} × _{S}C_{1})  (_{V3}C_{1} × _{S}C_{1}) 
Straight  (_{V3}C_{1} × _{S}C_{1}^{5})  (_{V3}C_{1} × _{S}C_{1}) 
Three of a kind  _{V}C_{1} × _{S}C_{3} × _{V1}C_{2} × _{S}C_{1}^{2} 
Two Pair  _{V}C_{2} × _{S}C_{2}^{2} × _{V2}C_{1} × _{S}C_{1} 
Pair  _{V}C_{1} × _{S}C_{2} × _{V1}C_{3} × _{S}C_{1}^{3} 
High Card  (_{V}C_{5}  (V3)) × (_{S}C_{1}^{5}  S) 
*The formula for straights is only correct for V ≥ 6 (because we need to take account that the Ace can be used at either end). If V = 5, we need to subtract 4 from the number of choices to pick from, not 3.
Below are the how the rankings change if we keep the number of values in a deck fixed at 13 (A,K,Q,J,T,9,8,7,6,5,4,3,2) and vary the number of suits in the deck. For each number of decks I've calculated the number of occurences of that hand, and the cardinal ranking of their strengths.
Suits:  1  2  3  4  5  6  7  8  16  32  

Five of a kind  13  1st  78  2nd  273  2nd  728  2nd  56,784  3rd  2,617,888  3rd  
Straight Flush  10  1st  20  1st  30  1st  40  1st  50  2nd  60  1st  70  1st  80  1st  160  1st  320  1st  
Four of a Kind  624  2nd  3,900  3rd  14,040  4th  38,220  4th  87,360  4th  4,542,720  4th  179,512,320  4th  
Full House  468  2nd  3,744  3rd  15,600  5th  46,800  5th  114,660  5th  244,608  5th  10,483,200  5th  383,784,960  6th  
Flush  1,277  2nd  2,554  4th  3,831  4th  5,108  4th  6,385  4th  7,662  3rd  8,939  3rd  10,216  3rd  20,432  2nd  40,864  2nd  
Straight  300  2nd  2,400  3rd  10,200  5th  31,200  6th  77,700  6th  168,000  6th  327,600  6th  10,485,600  6th  335,544,000  5th  
Three of a kind  7,722  5th  54,912  6th  214,500  7th  617,760  7th  1,471,470  7th  3,075,072  7th  123,002,880  7th  4,357,816,320  7th  
Two Pair  1,716  3rd  23,166  6th  123,552  7th  429,000  8th  1,158,300  8th  2,648,646  8th  5,381,376  8th  197,683,200  8th  6,754,615,296  8th  
Pair  22,880  5th  231,660  7th  1,098,240  8th  3,575,000  9th  9,266,400  9th  20,600,580  9th  41,000,960  9th  1,405,747,200  10th  46,483,374,080  10th  
High card  38,310  6th  306,480  8th  1,302,540  9th  3,984,240  10th  9,922,290  10th  21,453,600  10th  41,834,520  10th  1,339,011,120  9th  42,848,968,800  9th  
TOTAL  1,287  65,780  575,757  2,598,960  8,259,888  21,111,090  46,504,458  91,962,520  3,091,033,296  101,346,274,848 
Here are some takeaways:
When there is only one suit, all hands are either flushes or straight flushes! The straight flush is the rarest.
When a deck contains two suits, it's not possible to make four of a kind, three of a kind, or a full house. The straight flush is still the rarest hand, but a straight is less likely than a flush.
With three suits, all the standard poker hands are possible except four of a kind, but again the ranking of the flush and the straight are reversed.
With four suits, this is our vanilla deck, and the numbers correspond to those calculated earlier.
If we add a fifth suit, five of a kind is possible. This becomes the rarest hand, and the flush and the full house switch places.
With six suits (and beyond), five of a kind relinquishes the position of ranking highest, and this honour returns to the straight flush.
The rankings don't change from six to seven suits.
Nor do they change from seven to eight.
Things don't change again until 10 suits (not shown), when now it becomes more likely to have a pair than just a high card.
By 13 suits (not shown), the flush becomes the second ranking hand.
After 16 suits, the full house changes from fifth ranking to sixth ranking.
The rankings don't change from this point onwards.
What happens if we keep a deck with the standard four suits, but adjust the number of cards in every suit away from the standard 13?
The top table below shows decks with a range of cards up to a standard 13 card per suite deck.
N cards:  2  3  4  5  6  7  8  9  10  11  12  13  

Five of a kind  
Straight Flush  4  1st  12  1st  16  1st  20  1st  24  1st  28  1st  32  1st  36  1st  40  1st  
Four of a Kind  8  1st  24  1st  48  1st  80  2nd  120  3rd  168  3rd  224  3rd  288  2nd  360  2nd  440  2nd  528  2nd  624  2nd  
Full House  48  2nd  144  2nd  288  2nd  480  3rd  720  4th  1,008  4th  1,344  4th  1,728  4th  2,160  4th  2,640  4th  3,168  4th  3,744  3rd  
Flush  12  1st  68  2nd  204  2nd  480  3rd  980  3rd  1,816  3rd  3,132  3rd  5,108  4th  
Straight  1,020  4th  3,060  5th  4,080  5th  5,100  5th  6,120  5th  7,140  5th  8,160  5th  9,180  5th  10,200  5th  
Three of a kind  192  3rd  768  3rd  1,920  5th  3,840  7th  6,720  6th  10,752  6th  16,128  6th  23,040  6th  31,680  6th  42,240  6th  54,912  6th  
Two Pair  432  4th  1,728  5th  4,320  6th  8,640  8th  15,120  7th  24,192  7th  36,288  7th  51,840  7th  71,280  7th  95,040  7th  123,552  7th  
Pair  1,536  4th  7,680  7th  23,040  9th  53,760  9th  107,520  9th  193,536  9th  322,560  9th  506,880  9th  760,320  8th  1,098,240  8th  
High card  3,060  5th  17,340  8th  52,020  8th  122,400  8th  249,900  8th  463,080  8th  798,660  9th  1,302,540  9th  
TOTAL  56  792  4,368  15,504  42,504  98,280  201,376  376,992  658,008  1,086,008  1,712,304  2,598,960 
The lower table shows larger decks.
N cards:  13  14  15  16  32  256  4,096  

Five of a kind  
Straight Flush  40  1st  44  1st  48  1st  52  1st  116  1st  1,012  1st  16,372  1st 
Four of a Kind  624  2nd  728  2nd  840  2nd  960  2nd  3,968  2nd  261,120  3rd  67,092,480  3rd 
Full House  3,744  3rd  4,368  3rd  5,040  3rd  5,760  3rd  23,808  3rd  1,566,720  4th  402,554,880  4th 
Flush  5,108  4th  7,964  4th  11,964  4th  17,420  5th  805,388  5th  35,238,195,212  7th  38,336,971,972,739,100  8th 
Straight  10,200  5th  11,220  5th  12,240  5th  13,260  4th  29,580  4th  258,060  2nd  4,174,860  2nd 
Three of a kind  54,912  6th  69,888  6th  87,360  6th  107,520  6th  952,320  6th  530,595,840  5th  2,197,412,904,960  5th 
Two Pair  123,552  7th  157,248  7th  196,560  7th  241,920  7th  2,142,720  7th  1,193,840,640  6th  4,944,179,036,160  6th 
Pair  1,098,240  8th  1,537,536  8th  2,096,640  8th  2,795,520  8th  55,234,560  8th  268,481,495,040  8th  17,988,022,040,002,600  7th 
High card  1,302,540  9th  2,030,820  9th  3,050,820  9th  4,442,100  9th  205,373,940  9th  8,985,739,779,060  9th  9,775,927,853,048,470,000  9th 
TOTAL  2,598,960  3,819,816  5,461,512  7,624,512  264,566,400  9,291,185,992,704  9,832,259,989,126,990,000 
Here are some takeaways:
As there are only four suits it's always going to be impossible to make five of a kind.
Because there are only four suits, if we only have one distinct value for each card, there will be only four cards in the deck, so there is no way to make a five card hand! We need a minimum of two cards per suit to play poker.
With two numbers for each suit, in your five card hand, you either have four of a kind, or a full house.
With three values in each suit it's also possible to have three of a kind, or two pairs.
With four values in each suit it's possible to only have a pair for the first time.
Once we have five, or more, cards it's possible be able to make straights and straight flushes.
With five values, it's still not possible to just get a high card, as any five distinct cards in a set of five will always make a straight. Because of this, even though with five cards you can now make a flush, this will be a straight flush because they will be connected.
With six cards, both a straight flush and nonstraight flush are equally likely. It's also possible to get a high card only for the first time.
With a small number of values, it's much more likely to get a pair than a high card. As the number of cards increases, this changes (changing over at 12).
With large numbers of cards per suit, high cards dominate. Flushes are also common.
If you are bored one afternoon, it might be a fun exercise to dust off a little code to see the sensitivity impact of losing one card in a deck. If you have a deck of cards and your kids have lost one (or the dog has eaten it), how does this change the odds for poker hands? If you know what the missing card is, how does this impact the rankings? 
If you want to know how the odds change with the additional of wild cards, see my next article.
You can find a complete list of all the articles here.^{} Click here to receive email alerts on new articles.