Learn the Math Behind Your Favorite Card Tricks

Concerning various card tricks with a mathematical message

Human hand spreading a deck of cards

Boris Zhitkov/Getty Images

Editor’s Note: Published in 1957, this article comes from Martin Gardner’s legendary Scientific American column Mathematical Games. Read more in our special digital issue, Fun and Games.

Somerset Maugham’s short story “Mr. Know-All” contains the following dialogue:

“Do you like card tricks?”

“No, I hate card tricks.”

“Well, I’ll just show you this one.”


On supporting science journalism

If you're enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.


After the third trick, the victim finds an excuse to leave the room. His reaction is understandable. Most card magic is a crashing bore, unless it is performed by skillful professionals. There are, however, some “self-working” card tricks that are intensely interesting from a mathematical standpoint.

[Play science-inspired games, puzzles and quizzes in our new Games section]

Consider the following trick. The magician, who is seated at a table directly opposite a spectator, first reverses 20 cards anywhere in the deck. That is, he turns them face up in the pack. The spectator thoroughly shuffles the deck so that these reversed cards are randomly distributed. He then holds the deck underneath the table, where it is out of sight to everyone, and counts off 20 cards from the top. This packet of 20 cards is handed under the table to the magician.

The magician takes the packet but continues to hold it beneath the table so that he cannot see the cards. “Neither you nor I,” he says, “knows how many cards are reversed in this group of 20 which you handed me. However, it is likely that the number of such cards is less than the number of reversed cards among the 32 which you are holding. Without looking at my cards I am going to turn a few more face-down cards face up and attempt to bring the number of reversed cards in my packet to exactly the same number as the number of reversed cards in yours.”

The magician fumbles with his cards for a moment, pretending that he can distinguish the fronts and backs of the cards by feeling them. Then he brings the packet into view and spreads it on the table. The face-up cards are counted. Their number proves to be identical with the number of face-up cards among the 32 held by the spectator!

This remarkable trick can best be explained by reference to one of the oldest mathematical brain-teasers. Imagine that you have before you two beakers, one containing a liter of water; the other, a liter of wine. One cubic centimeter of water is transferred to the beaker of wine and the wine and water mixed thoroughly. Then a cubic centimeter of the mixture is transferred back to the water. Is there now more water in the wine than wine in the water? Or vice versa?

The answer is that there is just as much wine in the water as water in the wine. The amusing thing about this problem is the extraordinary amount of irrelevant information involved. It is not necessary to know how much liquid there is in each beaker, how much is transferred, or how many transfers are made. It does not matter whether the mixtures are thoroughly stirred or not. It is not even essential that the two vessels hold equal amounts of liquid at the start! The only significant condition is that at the end each beaker must hold exactly as much liquid as it did at the beginning. When this obtains, then obviously if x amount of wine is missing from the wine beaker, the space previously occupied by this wine must now be filled with x amount of water.

If the reader is troubled by this reasoning, he can quickly clarify it with a deck of cards. Place 26 cards face down on the table to represent wine. Beside them put 26 cards face up to represent water. Now you may transfer cards back and forth in any manner you please from any part of one pile to any part of the other, provided you finish with exactly 26 in each pile. You will then find that the number of face-down cards in either pile will match the number of face-up cards in the other pile.

Now try a similar test beginning with 32 face-down cards and 20 face up. Make as many transfers as you wish, ending with 20 cards in the smaller pile. The number of face-up cards in the large pile will of necessity exactly equal the number of face-down cards among the 20. Now turn over the small pile. This automatically turns its face-down cards face up and its face-up cards face down. The number of face-up cards in both groups will therefore be the same.

The operation of the trick should now be clear. At the beginning the magician reverses exactly 20 cards. Later, when he takes the packet of 20 cards from the spectator, it will contain a number of face-down cards equal to the number of face-up cards remaining in the deck. He then pretends to reverse some additional cards, but actually all he does is turn the packet over. It will then contain the same number of reversed cards as there are reversed cards in the group of 32 held by the spectator. The trick is particularly puzzling to mathematicians, who are apt to think of all sorts of complicated explanations.

Many card effects known in the conjuring trade as “spellers” are based on elementary mathematical principles. Here is one of the best. With your back to the audience, ask someone to take from one to 12 cards from the deck and hide them in his pocket without telling you the number. You then tell him to look at the card at that number from the top of the remainder of the deck and remember it.

Turn around and ask for the name of any individual, living or dead. For example, someone suggests Marilyn Monroe (the name, by the way, must have more than 12 letters). Taking the deck in your hand, you say to the person who pocketed the cards: “I want you to deal the cards one at a time on the table, spelling the name Marilyn Monroe like this.” To demonstrate, deal the cards from the top of the deck to form a face-down pile on the table, taking one card for each letter until you have spelled the name aloud. Pick up the small pile and replace it on the deck.

“Before you do this, however,” you continue, “I want you to add to the top of the deck the cards you have in your pocket.” Emphasize the fact, which is true, that you have no way of knowing how many cards this will be. Yet in spite of this addition of an unknown number of cards, after the spectator has completed spelling Marilyn Monroe, the next card (that is, the card on top of the deck) will invariably turn out to be his chosen card!

The operation of the trick yields easily to analysis. Let x be the number of cards in the spectator’s pocket and also the position of the chosen card from the top of the deck. Let y be the number of letters in the selected name. Your demonstration of how to spell the name automatically reverses the order of y cards, bringing the chosen card to a position from the top that is y minus x. Adding x cards to the deck therefore puts y minus x plus x cards above the selected one. The x’s cancel out, leaving exactly y cards to be spelled before the desired card is reached.

A more subtle compensatory principle is involved in the following effect. A spectator is asked to select any three cards and place them face down on the table without letting the magician see them. The remaining cards are shuffled and handed to the magician.

“I will not alter the position of a single card,” the magician explains. “All I shall do is remove one card which will match in value and color the card you will select in a moment.” He then takes a single card from the pack and places it face down at one side of the table.

The spectator is now asked to take the remaining cards in hand and to turn face up the three cards he previously placed on the table. Let us assume that they are a nine, a queen and an ace. The magician requests that he start dealing cards face down on top of the nine, counting aloud as he does so, beginning the count with 10 and continuing until he reaches 15. In other words, the spectator deals six cards face down on the nine. The same procedure is followed with the other two cards. The queen, which has a value of 12 (jacks are 11, kings 13), will require three cards to bring the count from 12 to 15. The ace (1) will require 14 cards.

The magician now has the spectator total the values of the three original face-up cards, and note the card at that position from the top of the remainder of the deck. In this case the total is 22 (9 plus 12 plus 1), so he looks at the 22nd card. The magician turns over his “prediction card.” The two cards match in value and color!

How is it done? When the magician glances through the deck to find a “prediction card,” he notes the fourth card from the bottom and then removes another card which matches it in value and color. The rest of the trick works automatically. I leave to the reader the easy task of working out an algebraic proof of why the trick cannot fail.

The ease with which cards can be shuffled makes them peculiarly appropriate for demonstrating a variety of probability theorems, many of which are startling enough to be called tricks. For example, let us imagine that two people each hold a shuffled deck of 52 cards. One person counts aloud from 1 to 52; on each count both deal a card face up on the table. What is the probability that at some point during the deal two identical cards will be dealt simultaneously?

Most people would suppose the probability to be low, but actually it is better than 1/2! The probability there will be no coincidence is 1 over the transcendental number e. (This is not precisely true, but the error is less than 1 over 10 to the 69th power. The reader may consult page 47 in the current edition of W. Rouse Ball’s Mathematical Recreations and Essays for a method of arriving at this figure.) Since e is 2.718..., the probability of a coincidence is roughly 17/27 or almost 2/3. If you can find someone who is willing to bet you even odds that no coincidence will occur, you stand a rather good chance to pick up some extra change.

Scientific American Magazine Vol 197 Issue 3This article was originally published with the title “Mathematical Games” in Scientific American Magazine Vol. 197 No. 3 (), p. 220
doi:10.1038/scientificamerican0957-220