The de Bruijn sequence card trick
Five people each take a card and say one word: red, or black. That is all you get, and it is enough to name every one of their cards.
Set up in advance — thirty-two cards in a known order, and five colors to turn into five cards. What that costs is right under the demo.
Do it yourself
The packet has been cut where you cannot see, and five people have taken the top five cards. Ask them their colors one at a time.
·····
What it costs to perform
This one is set up in advance, and that is worth knowing before you fall for it. Two things have to be true before you can perform it:
- Thirty-two cards, arranged beforehand. You cannot borrow a deck and do this. The order is further down the page and takes a couple of minutes to lay out.
- You have to turn five colors into five cards. That means learning thirty-two starts and sixteen jumps — there is a memorizer for them on this page — or carrying the cheat sheet and reading it while five people watch you.
What you get in exchange is the thing most set-up tricks cannot offer: the spectator can cut it, as often as they like. A cut is the one thing this arrangement does not care about, so the packet can be handled in the open.
It is self-working in the sense this site means — no sleight of hand, no moves, nothing to palm. It is not impromptu. On the trick list that is the difference between Si Stebbins, which is a stack you build first, and the 21 card trick, which needs nothing at all.
32
checked in your browser, not asserted
Why five colors are enough
The packet is thirty-two cards, arranged so that no run of five colors repeats anywhere in it. Five people in a row hand you five colors, and there is exactly one place in the packet those five could have come from.
Five people, each saying one of two words, can produce 25 = 32 different answers. A packet of thirty-two cards has thirty-two places to cut. Those two numbers being the same is the whole trick: there are exactly enough patterns to give every cut its own one, with none spare and none repeated.
That is what a de Bruijn sequence is. Written as bits, with 1 for red and 0 for black, it is a cycle of thirty-two digits in which every five-digit string appears once and once only. The number above is this page counting its own patterns when it loaded, and checking that each one decodes back to the cut it came from.
Notice what the person is not doing. They are not naming a card, or remembering a number, or being steered. They say a color, which is a fact about the card they are holding, and five such facts are a coordinate.
Why a cut does not ruin it
The sequence is cyclic, and that word is carrying the trick. Cutting takes cards off the top and puts them on the bottom, which changes where the packet starts and nothing else. Every card still follows the card it followed before, so every run of five is still one of the thirty-two runs.
This is the difference between a stack that has to be protected and a stack that can be handled. The spectator cuts as often as they like, and the arrangement they are trying to disturb is the one thing a cut leaves alone.
The decoder
Set the five colors the way your spectators called them, and it names each person's card. It works on any five colors, including ones this page did not deal.
The cheat sheet
All thirty-two patterns, what each one names, and the cards in the order the five people are holding them. This is the table to photograph if you would rather carry it than learn it.
Or learn the thirty-two
A table you read at the table is still a table you are reading. This drills the same thirty-two, and it drills the two things you actually need: which card the five colors start on, and how to walk forward from it.
Half the packet is nothing to learn. Each color runs in deck order — the blacks from the ace of clubs through to the three of spades, the reds from the ace of hearts through to the three of diamonds — so when two people in a row say the same color, the second card is simply the next one along. Ace of clubs, two of clubs. Six of hearts, seven of hearts. Only the sixteen places where the color changes have to be memorized, and the spectators tell you which kind of step is coming, because saying their color is exactly that.
So the whole load is thirty-two starts and sixteen jumps, and the third stage is both at once: five colors through to the card the fifth person is holding. Getting one right at any speed is what opens the next; getting it right under two and a half seconds is what opens the next stage, because knowing a card and knowing it without hunting for it are two different achievements. Nothing here needs an account, and the drill works the same whether or not you ever leave an address.
The memorizer
The packet, in order
Sixteen reds and sixteen blacks, which is what a cycle of order five works out to. Which card sits on which color does not matter to the method — only the color does — so these are taken in deck order, which is the easiest arrangement to lay out and to check.
What a full deck costs you
Six people would need every six-color pattern to be different, and there are 26 = 64 of those. Sixty-four is more than a deck holds, so a fifty-two-card version has to give something up: either some patterns go missing, or some cards are never really in play. That is why the honest version of this trick is thirty-two cards and five people, and why the versions built on a full deck come with a paragraph of small print.
Where this comes from
- The sequence: de Bruijn, N. G., "A combinatorial problem", Koninklijke Nederlandse Akademie van Wetenschappen, 1946. De Bruijn recorded afterwards that Camille Flye Sainte-Marie had counted the binary case in 1894, so the name credits the later paper. De Bruijn sequence on Wikipedia carries both.
- The card application: Diaconis, P. and Graham, R., Magical Mathematics, Princeton University Press, 2011, chapter 2, "In Cycles". Paperback from Amazon.
- No single inventor is credibly attributable for the trick itself. It circulates widely in the magic literature under several names, and this page describes the mechanism rather than any one person's handling of it.
- The sequence on this page is generated, not copied. It is built by Duval's algorithm over Lyndon words when the page loads, and then checked: thirty-two windows, thirty-two distinct patterns, and every pattern decoding back to its own cut. The same check runs in this site's test suite on every change, so a broken packet would stop a release.
Questions people ask
What is the de Bruijn sequence card trick?
Thirty-two cards are arranged so that their colors follow a de Bruijn sequence. Somebody cuts the packet, and five people in a row take the top five cards. Each says only whether their card is red or black.
Those five colors happen at exactly one place in the packet, so they name where the cut fell and therefore name all five cards, without a single face being seen.
How does the de Bruijn card trick work?
A binary de Bruijn sequence of order five is a cycle of thirty-two bits in which every one of the thirty-two possible five-bit strings appears exactly once. Read red as 1 and black as 0, and arrange thirty-two cards to match.
Five consecutive cards then give a five-bit string, and because each string occurs once, that string identifies the position in the cycle. Knowing the position means knowing which five cards are there.
Why does cutting the packet not ruin the trick?
Because the sequence is cyclic. A cut takes cards from the top and puts them on the bottom, which rotates the starting point without changing the order anything follows. Every run of five in the cut packet was already a run of five in the original, so all thirty-two patterns survive.
This is why the spectator can genuinely handle the packet, and it is the part that makes the trick worth performing rather than only worth reading about.
How many cards do you need for the de Bruijn card trick?
Thirty-two, for five people. The count is fixed by the arithmetic rather than chosen: five colors give two to the fifth power, which is thirty-two patterns, so thirty-two is the longest packet in which every run of five can still be different.
Six people would need sixty-four cards, which is more than a deck holds, so a full fifty-two-card version has to give something up.
How do you memorize the de Bruijn sequence for the card trick?
You do not memorize thirty-two hands, and you do not need the cut number at all. You learn which card a run of five colors starts on, which is thirty-two items, and then you walk forward.
Walking forward is nearly free, because each color runs in deck order: when two people in a row say the same color, the second card is the next one along. Only the sixteen places where the color changes have to be learned. That is forty-eight items rather than a hundred and sixty, and the memorizer on this page drills them in that order.
Who invented the de Bruijn sequence?
It is named for Nicolaas Govert de Bruijn, a Dutch mathematician who published on the binary case in 1946. He noted afterwards that Camille Flye Sainte-Marie had counted them in 1894, so the naming credits the wrong century.
The card application has no single clear inventor and circulates widely in the magic literature; Persi Diaconis and Ron Graham give it a chapter in Magical Mathematics.
More
This sits under mathematical card tricks, which collects the tricks that run on arithmetic rather than on sleight of hand. The shuffle that leaves an arrangement standing is the Gilbreath principle, the shuffle that returns a deck to where it started is the faro shuffle, and a stack you can read a whole deck from is Si Stebbins.