Mathematical Algorithm

21-Card Trick

Deterministic convergence through ternary subdivision

1
2
3
Remember any card, then click the column it's in

Your card is:

How It Works
21 cards are dealt into 3 columns of 7. Each round, you tell the algorithm which column contains your card. The chosen column is placed in the middle of the three stacks when gathering them back together. After 3 rounds, your card is guaranteed to be at position 11 (the centre) — a consequence of the mathematical structure of the rearrangement, not luck.
Learn How This Works ▼

The Trick

21 cards are dealt into 3 columns of 7. The magician asks which column contains your card. The cards are gathered — with the chosen column placed in the middle. After 3 rounds, the card is always at position 11 (the exact centre of 21 cards).

Why It Works (The Mathematics)

After round 1: Your card is somewhere in positions 8–14 (the middle 7).

After round 2: Your card is in positions 10–12 (the middle 3).

After round 3: Your card is at position 11 (the exact middle).

Each round places the chosen group of 7 in the middle of the deck. Within that group, the card's position is also narrowed to the middle third. The three rounds of ternary subdivision converge deterministically to the centre.

Formally

The algorithm performs a base-3 digit extraction. Each round identifies one ternary digit of the card's position within the chosen column. Three rounds = three digits = uniquely identifies 1 of 33 = 27 positions. Since 21 < 27, three rounds always suffice.

Complexity

Time: O(1) — exactly 3 rounds, regardless of which card is chosen

Space: O(n) where n = 21 (the card array)

This is a deterministic, non-adaptive algorithm — the same 3 steps work for any card.