How much information can be stored by ordering 52 playing cards?

Well, there are "52!" (52 factorial, or 52 x 51 x 50 ....) possible orderings of 52 cards. That's:

80,658,175,170,943,878,571,660,636,856,403,766,975,289,505,440,883,277,824,000,000,000,000 possibilities.

You can come up with a way to count all those possibilities, and assign each one a number. A deck that's completely in-order might be #1. A deck with the first two cards swapped could be called #2, and so on. Basically, then, we have a way of storing any number from 1 up to that 68-digit monstrosity up there.

That means you can store any arbitrary 67-digit number (since some 68-digit numbers are too big), which means, for example, you have enough room encode six 10-digit phone numbers by writing them out one after the other and using that "number" to determine the order.

We can calculate how many numerical digits fit by using the formula: log(52!)/log(10), i.e. the base-10 logarithm of that giant number, which tells you how many base-10 digits it is. log(52!)/log(10)=67.9, which means that it takes 68 digits to represent the number, and that all 67-digit numbers will "fit."

We can try different number bases for different kinds of information. log(52!)/log(2)=225.6, meaning that our deck of cards can store any base-2 number that is 225 digits long or less. In other words, the order of a deck of cards is 225 bits of information. That's enough for 28 eight-bit bytes, or 32 seven-bit ASCII characters.

What if we want to hide a simple text message? If we limit our alphabet to 26 letters plus a space and a period, those 28 characters could serve as the "digits" of a base-28 "number" and we could store (log(52!)/log(28)=46.9) a 46 character messsage!

I chose to make A=1, B=2 etc, with the space character equal to 27 and the period as 0. Just as we do in base-10 numbers, each digit column to the left is worth 28 times more. Thus "A"=1, "B"=2, "A."=28, "AA"=29, "AB"=30, "B."=56, "BA"=57 etc.

The order of the cards

The next step is to come up with a way to count all the possible orders of cards. Let's use a deck of four "cards" as an example, and call the cards A, B, C, and D.

Four cards have 4! possible orders, or 4 x 3 x 2 x 1 = 24. There are many possible ways to assign a number to a particular order, I'll describe just one possibility.

If we start with an empty grid with 4 positions to place the cards, there are 4 possibilities for the "A" card, followed by 3 for the "B" card, two choices for "C" and then "D" goes in the only remaining place.

Our four choices for placing the "A" card are: "A---", "-A--", "--A-", and "---A". Placing cards from left to right we can skip zero, one, two, or three spaces before putting down the "A". Skipping zero spaces means putting the "A" in the first available slot.

Once A has been placed, there are then three possibilities for B. So, we can skip zero, one, or two places before putting down the "B". If we skipped two spaces for "A" so that we have "--A-" our three "B" choices are: "B-A-", "-BA-", or "--AB".

Now that A and B have been placed, there are only two possibilities for C. If we have "-BA-" our only choices are "CBA-" or "-BAC", zero skips or one skipped space.

And finally, D is placed in the only remaining slot.

To conver our big "message number" into the appropriate number of skip values, we use division, using the remainder each time as the skip-value for a particular card. With our deck of 52 cards, our first division is by 52, with the remainder used to determine how many places are skipped in placing the first card. The second division is by 51, as there are only 51 positions left to fill in the deck. The next division is by 50, and so on down to the last division, which is by 1 which always leaves a remainder of zero, meaning the last card never skips any places. (There's only one space left!)

Back to our four-card example, if we want to encode pattern #18, we first divide 18 / 4 = 4 with a remainder of 2, so that would be two skips for the A card. Next we take our result (4) and divide by 3: 4 / 3 = 1 with a remainder of 1, so that's one skip for B. Finally, 1 / 2 = 0 with a remainder of 1, so one skip for C. The last card, D, would be 0 / 1 = 0 with a remainder of 0, which is good, because there should never be any skips for the last card, as there's only one remaining place it can go! This would all result in the pattern "DBAC".

Decoding the order

It turns out there is a simple rule we can use to be able to tell what the choices for A, B, and C had been. When we look at the order, for each card ask how many "bigger" cards there are to its left, assuming that "B" is bigger than "A", and "C" is bigger than "B" etc.

If our pattern is "DBAC" we see that "A" has two bigger letters to its left, B has one, and C has one. (D and B are both to the left of C, but only D is bigger). This is eactly how many "skips" were done when originally placing the letters! "A" skipped two spaces, "B" skipped one, and "C" skipped one.

To convert the number-of-skips for A, B, and C into one single "pattern number" we reverse the division process and multiply each one by the number of possibilities that came before it, and then add them together. B is multiplied by 4, and C is multiplied by 12 (which is 4 x 3). So we have 2 + (1 x 4) + (1 x 12) = 18, so pattern "DBAC" is pattern #18.

Here's the full grid showing the cards and how many "skipped positions" there were for A, B, and C:

##  Pattern  A-skips B-Skips C-skips
 0  A B C D     0       0       0
 1  B A C D     1       0       0
 2  B C A D     2       0       0
 3  B C D A     3       0       0
 4  A C B D     0       1       0
 5  C A B D     1       1       0
 6  C B A D     2       1       0
 7  C B D A     3       1       0
 8  A C D B     0       2       0
 9  C A D B     1       2       0
10  C D A B     2       2       0
11  C D B A     3       2       0
12  A B D C     0       0       1
13  B A D C     1       0       1
14  B D A C     2       0       1
15  B D C A     3       0       1
16  A D B C     0       1       1
17  D A B C     1       1       1
18  D B A C     2       1       1
19  D B C A     3       1       1
20  A D C B     0       2       1
21  D A C B     1       2       1
22  D C A B     2       2       1
23  D C B A     3       2       1
This is where math is fun: This concept, already complicated at 4 cards, scales all the way up to a full 52 card deck! You just need a really big calculator to handle the large numbers involved. The first card's skips have a value of 1, the next card's are 52, next 52 x 51 = 2652, then 52 x 51 x 50 = 132600 and so on.

All that is left is an agreed upon order for the cards in a deck. I use the order: Clubs, Diamonds, Hearts, Spades, with each suit ordered from Deuce up to Ace, meaning that the first card is the Deuce of Clubs, and the last card is the Ace of Spades.

Go back to the demonstration.