How do you shuffle a pack of cards? Our shuffling is very unimpressive, we've even been known to resort to jumbling them around in a big pile on the table. But good news – here is how you shuffle like a professional!

How to shuffle perfectly

Take a pack of cards and split the pack into two equal halves (we're assuming your pack, like an ordinary 52-card pack, has an even number of cards). Now interleave them perfectly: top card from the first pile, top card from the second pile, next card from the first pile, next card from the second pile and so on. This is exact interleaving of two halves of the pack is called a *perfect shuffle*.

Will Houstoun demonstrating a perfect shuffle (Video: Will Houstoun)

After a perfect shuffle, your pack will be shuffled in one of two ways. If the first pile was the top half of the pack, then the top card of your shuffled pack will be the top card of the original pack, and the bottom card of the shuffled pack will be the bottom card of the original pack. This is called an *out-shuffle*, and it fixes the top and bottom cards of the pack, they remain in their original position, while the other cards are interleaved.

If, like us, you are not a magician, you'll have to do this slowly and methodically. If you are a card player, or an excellent magician like Will Houstoun, you can do it almost instantly as you can see in the video!

If you switch your piles – the bottom half becomes the first pile and the top half the second pile – and then interleave the piles in the same way, you get the other type of perfect shuffle, called an *in-shuffle*.

**An out-shuffle in action...**

Suppose your pack consisted of the following 12 cards in this order, top to bottom:

Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen

You split the pack exactly in half:

A, 2, 3, 4, 5, 6

in the first pile, and

7, 8, 9, 10, J, Q

in the second pile.

Then an out-shuffle would reorder the cards in this way:

A, 7, 2, 8, 3, 9, 4, 10, 5, J, 6, Q

The top card, the Ace, and the bottom card, the Queen, of the original pack are fixed as the top and bottom card of the shuffled pack after an out-shuffle.

**...and an in-shuffle in action**

This time we swap the piles so the bottom half of the original pack is in the first pile:

7, 8, 9, 10, J, Q

and the top half of the pack is in the second pile:

A, 2, 3, 4, 5, 6.

Then an in-shuffle would reorder the cards in this way:

7, A, 8, 2, 9, 3, 10, 4, J, 5, Q, 6

What could a magician do with a perfect shuffle?

To see a perfect shuffle in action, we were lucky enough to speak with Will Houstoun, a professional conjuror and the Magician in Residence at the Imperial College London and Royal College of Music Centre for Performance Science. As you'd expect, Houstoun has amazing physical control over the cards as you can see from the video. He can even do a variation of a perfect shuffle where he perfectly interleaves the cards two at a time, rather than one at a time. His control of the cards is incredible!

You can listen to Will Houstoun talk about his shuffling magic in this podcast!

"Magicians are very interested in any way that you can make something impossible seem to happen," said Houstoun. "And knowing what is likely to happen to a pack of cards when it gets mixed up is part of that." Imagine if you wanted to begin with the cards in a particular order but you wanted people to think that the pack had been thoroughly shuffled. "Not that a magician would ever do such a thing!" Houstoun assured us.

"If you do eight perfect shuffles in a row [of a standard 52 card pack], the out-shuffles where you keep the top and bottom cards the same, then the deck goes back to the original order after eight repetitions of those out-shuffles. Admittedly it would take quite a long time, but if you wanted somebody to think that the deck was well mixed at the beginning of a trick, you could give it eight of these shuffles. [Everyone else] would then be 100% certain that the cards were well mixed, as they'd seen you mix them quite a lot, but in fact you would have your order ready to go." (You can see a mathematical proof of why this works, at the end of the original version of this article.)

What could a magician do with an imperfect shuffle?

Our favoured method for an imperfect shuffle!

An *imperfect shuffle* is really what we have in mind when we think of a normal, fair, shuffle. "An imperfect shuffle is the best shuffle possible, as a shuffle's real purpose it to mix up the cards in random fashion," says Houstoun. To do an imperfect shuffle you might split the pack into roughly half and half, and then alternate the cards from the two halves in a more random fashion – with clumps of two or three cards alternating, as well as the occasional single card too. That randomness in how the cards interweave from the two halves is the thing that makes it a fair shuffle.

Imperfect shuffles are interesting to mathematicians too. "Persi Diaconis, who's a statistician as well as a very good magician, did work on the optimum number of shuffles to mix a pack of cards randomly", says Houstoun. Diaconis developed a procedure where you would undercut about a third of the pack (so a third of the pack gets cut from the bottom of the pack and placed on the top), then split the cards approximately in half, and then you give them an imperfect shuffle as described above. "If you repeat this procedure seven times that gives you the best balance between the number of shuffles performed and the impact that has on destroying the orders that could be located in the pack at the end of the process."

This mathematical understanding is useful in practice in places like casinos, where the amount of money they make relies on the randomness they expect to be found in a shuffled pack of cards: "The fairer the shuffle, the better it is for the casino, because they will be able to take advantage of their mathematical edge in the game's construction. That means they’ll win more than the player does." However, everytime the dealer is shuffling the cards, people are not playing cards or laying bets, so the casino has to decide on a process for shuffling that balances the randomness with the amount of bets that they can get out of customers.

Perfect magic

The essence of an imperfect shuffle is that you don't want to end up with any particular, predictable order in the shuffled pack of cards. When we try to think of a special ordering of a pack of cards, we might think of one where the cards are in face value order, grouped in their suits, as they usually are with a new deck of cards. But one of Houstoun's most amazing card tricks plays with this idea of what orders we should think of as important.

Will Houstoun and Jim Carter on The Next Great Magician from Will Houstoun on Vimeo.

After Houstoun and his audience have totally mixed up the pack of cards, we're not surprised to see a totally random looking order in the shuffled pack of cards. And the randomness of this order is emphasised by the huge surprise at the end of the trick.

Although Houstoun obviously couldn't divulge the secret behind the magic of the trick, he could tell us what motivated him to develop the trick: "I was thinking about the question of order, and why one thinks some orders are very important and some are not. A mixed up deck of cards, for example, is instantly dismissed. A pack of cards in new deck order is something people think is important. I thought it would be fun to do a trick that explores how an order that is seemingly unimportant is actually precise and is interesting in its own particular way."

We may have started out learning how to shuffle perfection, but actually it's imperfection that we really want whether we are playing cards at home against a friend, or betting against the house at a casino. As well as magic there is a great deal of maths hidden within a card shuffle – something you can find out more about behind tomorrow's door of the *Plus* advent calendar 2021.

*Return to the Plus advent calendar 2021.*

*This article is part of our collaboration with the Isaac Newton Institute for Mathematical Sciences (INI), an international research centre and our neighbour here on the University of Cambridge's maths campus. INI attracts leading mathematical scientists from all over the world, and is open to all. Visit www.newton.ac.uk to find out more.*