Subscribe

The Maths of a Perfect Shuffle and Why Seven Is the Magic Number

Hands riffle shuffling a deck of playing cards above a green felt table
A riffle shuffle mid-bridge, the cards falling from each half in small, uneven clumps.

Shuffle a deck of cards perfectly eight times and it returns to exactly where it started. Shuffle it carelessly seven times and it is, for practical purposes, random. Both facts say something odd about order.

Here is a trick that requires no sleight of hand, only patience. Take an ordinary deck of 52 cards, in order. Cut it exactly in half. Then interleave the halves perfectly, one card from each side in turn, so the top card stays on top. Do that eight times. The deck is back in its original order.

Magicians call this a faro shuffle, and the ones who can do it reliably are rare, because it requires splitting the deck at precisely 26 cards and dropping single cards from each hand in strict alternation. Mathematicians find it interesting for a different reason. It shows that a shuffle, done perfectly, has no randomness in it at all.

Why eight

A perfect shuffle is a fixed rearrangement. Each card moves to a predictable new position. If you number the positions from 0 to 51, a card in position n moves to position 2n, wrapped around the deck using arithmetic modulo 51. The bottom card stays at the bottom.

To get back to the start, you need to find how many doublings bring every position home. The answer is the smallest number k for which 2 raised to the power k leaves a remainder of 1 when divided by 51. Work it out and you find that 2⁸ is 256, and 256 is five lots of 51 plus 1. So eight shuffles, and the deck is home.

Change the deck size and the answer jumps around unpredictably. A deck of 50 cards takes 21 perfect shuffles. A deck of 64 takes only six. The cycle length depends on the number theory of the deck, and it is one of those small, satisfying puzzles that keeps showing up in courses on group theory.

Real shuffles are messier

Nobody at a kitchen table shuffles perfectly. A real riffle shuffle splits the deck roughly in half, and cards fall from each thumb in clumps of one, two or three. That messiness is exactly what produces randomness.

In 1992, two statisticians published a careful analysis of how many ordinary riffle shuffles it takes to mix a deck well. They modelled the shuffle as a random process and measured how far the deck's arrangement was from truly random after each round. The result has become a small piece of folklore.

  • After four or five shuffles, the deck is still very far from random. Long runs of the original order survive.
  • At around seven shuffles, the distance from randomness drops sharply.
  • After that, extra shuffles help only a little.

The drop is unusually sudden. For several shuffles very little seems to happen, and then, over one or two more, the order collapses. Mathematicians call this a cutoff, and it has since been found in many other mixing processes, from the diffusion of particles to the way information spreads through a network.

What this means at the card table

If you play cards at home, seven riffle shuffles is a good habit. Most people do three or four, which leaves enough of the previous hand's order in the deck that a sharp player could, in principle, take advantage. Casinos, which care a great deal about this, use automatic shufflers or long sequences of riffles, washes and cuts.

The overhand shuffle, where you drop small packets from one hand to the other, is far worse. By one estimate it takes thousands of overhand shuffles to randomise a deck as thoroughly as seven riffles.

Order hiding in disorder

There is something philosophically pleasing about the pair of results. The perfect shuffle looks like the most thorough mixing possible, yet it is completely reversible and returns everything to its place. The sloppy, human shuffle, full of mistakes and uneven clumps, is the one that actually destroys order.

Randomness, in other words, comes from imperfection. A deck needs a slightly clumsy pair of hands to forget where it has been.

Henrik Aalto

Henrik Aalto Science writer covering soil, weather and other slow systems. Former field ecologist.

Subscribe to my newsletter to get the latest updates and news

Subscribe Follow via RSS instead

Member discussion