Nim cover
Board Games

Nim - Rules, History & Strategy Guide

Nim is a two-player mathematical strategy game played with rows of matchsticks, classically 1, 3, 5 and 7. On each turn you remove any number of sticks from a single row; under the classic misère rule, whoever takes the last stick loses. Games are pure skill and finish in two to five minutes.

Reviewed & updated

History & Origins

Nim is ancient in spirit, but its modern fame is mathematical: in 1901 Harvard’s Charles Bouton published the complete solution and coined the name, making Nim the first game ever fully solved in print. Fifty years later it became the first game a computer was built to play, when Ferranti’s NIMROD, a wall of lights and switches, took on the public at the 1951 Festival of Britain and beat nearly everyone who tried it.

The game reached popular legend through the 1961 film Last Year at Marienbad, whose characters play the 1-3-5-7 layout obsessively; that arrangement has been called the Marienbad game ever since. Nim also seeded an entire branch of mathematics, combinatorial game theory, where the Sprague-Grundy theorem shows every impartial game is secretly a game of Nim.

How to Play

Nim is a pure duel with no luck: four rows of sticks, alternating turns, and one simple move — take sticks from a single row. The whole game is deciding how many.

  1. Set up four rows of 1, 3, 5 and 7 matchsticks.
  2. On your turn, remove one or more sticks, all from the same row.
  3. Alternate turns; there is no passing.
  4. Misère rule (classic): whoever is forced to take the last stick loses.
  5. Normal rule: whoever takes the last stick wins. Agree on the rule before starting.

Strategy Tips

  • Learn the nim-sum: XOR the row sizes in binary; a move that leaves nim-sum zero puts your opponent in a lost position.
  • Memorize the safe shapes: 1-1, 2-2, 1-2-3 and any two equal rows are balanced (nim-sum zero).
  • Mirror strategy: with two equal rows left, copy your opponent’s move in the other row and you cannot lose.
  • Misère endgame: when your move would leave only single sticks, leave an ODD number of them.
  • From the 1-3-5-7 start the position is already balanced, so moving second wins with perfect play; offer your opponent the first move.

Variations

Nim is a family: the 21 game (take 1-3 from a single pile of 21), Northcott’s game on a checkerboard, and turning games like Mock Turtles are all Nim in disguise via the Sprague-Grundy theorem. Layouts vary from three rows (3-5-7) to five and more; every layout is solved by the same nim-sum arithmetic, which is why the game remains a staple of mathematics classrooms.

Play Nim on Arcadia

Play Nim on Arcadia to learn the nim-sum, spring the misère trap, and out-count NIMROD itself.

Quick Answers

What is the nim-sum?

The XOR of all row sizes written in binary. If the nim-sum after your move is zero, your opponent is in a losing position no matter what they do. This 1901 result by Charles Bouton made Nim the first fully solved game.

How does the misère rule change strategy?

Only at the very end. Play the normal zero-sum strategy until your move would leave nothing but single sticks, then leave an odd number of them so your opponent must take the last one.

Who wins Nim with perfect play?

It depends on the layout. The classic 1-3-5-7 start is balanced (nim-sum zero), so the second player wins with perfect play — which is why experts politely let you move first.

What was NIMROD?

The first computer built to play a game: a Ferranti machine exhibited at the 1951 Festival of Britain that played Nim with lights for sticks and beat almost every human challenger.

Can I play Nim online for free?

Yes. Arcadia offers free Nim in your browser with misère and normal rules and a perfect-play NIMROD difficulty — no download or account required.

Is Nim a game of luck or skill?

Pure skill. There are no dice and no hidden information, and Charles Bouton proved in 1901 that every position is either winning or losing for the player to move, with an exact rule for telling which. The only luck in Nim is an opponent who miscounts.

Who invented Nim and where does the name come from?

Nobody knows who invented it — simple take-away games appear in many cultures and are probably very old. What is documented is the mathematics: Charles Bouton of Harvard named the game and published its complete solution in 1901. The name is usually traced to the German nimm or the archaic English nim, both meaning “take”.

What is the Marienbad game?

It is misère Nim with the 1-3-5-7 layout, named after Alain Resnais’s 1961 film Last Year at Marienbad, in which a character plays it repeatedly with matchsticks and never loses. The film made that layout the standard image of Nim, and it briefly turned the game into a popular craze.

What is the Sprague-Grundy theorem?

It is the result that makes Nim the measuring stick of game theory: Roland Sprague (1935) and Patrick Grundy (1939) independently proved that every impartial game under normal play is equivalent to a single Nim heap of some size. In other words, once you can play Nim perfectly, you hold the key to a whole class of games.

Was NIMROD the first video game?

Historians usually say no, because NIMROD displayed the game on panels of light bulbs rather than a screen — screen-based candidates such as OXO (1952) and Tennis for Two (1958) came later. NIMROD’s claim is different: built by Ferranti for the 1951 Festival of Britain, it was the first computer constructed purely to play a game.

How do you win the 21 game?

The 21 game is Nim in disguise: a single pile of 21, take one to three per turn, and whoever takes the last one loses. The winning method is to always leave your opponent a pile of one more than a multiple of four — 17, 13, 9, 5 and finally 1 — so every pair of moves shrinks the pile by exactly four.

Can a game of Nim end in a draw?

No. Every turn removes at least one stick, so the standard 1-3-5-7 game must end within 16 moves, and there is no repetition or stalemate to hide behind. One player always has a forced win from any position — the whole question is whether they can find it.

How long does a game of Nim take?

Two to five minutes is typical: the standard layout holds only 16 sticks, so games cannot drag. On Arcadia you can play free in your browser with misère or normal rules, against a Casual opponent that makes human mistakes or a perfect-play NIMROD difficulty.