Strategy Board Games

Nim Game Online Free

Take as many sticks as you like from any one row. The player who takes the last stick wins, unless you choose the Last loses version.

 

Tap a stick to pick it and every stick to its right, then tap it again to take them.

What is Nim?

Nim is a two-player strategy game played with rows of sticks, stones or coins. On your turn you take any number of objects from a single row. In the normal game, the player who takes the last object wins. In the “misère” version, they lose.

Nim is the most famous game in mathematics. In 1901 Charles L. Bouton of Harvard published its complete winning strategy, the nim-sum: write each row size in binary and combine them with exclusive or (XOR). If you always leave a nim-sum of 0, you can’t lose. The computer on Hard plays this way.

More strategy board games

See all strategy board games →

How to play Nim Game

  1. The sticks are laid out in rows: 3, 4 and 5, or 1, 3, 5 and 7. Blue moves first.
  2. On your turn, take one or more sticks from one row. You can take a whole row, but you can’t take from two rows at once.
  3. Tap a stick to choose it and every stick to its right, then tap it again to take them. Tap a different stick to change your mind.
  4. Players keep taking turns until every stick is gone.
  5. In normal play, whoever takes the last stick wins. In Last loses, whoever takes the last stick loses. Play against the computer at Easy, Medium or Hard, or choose 2 Players to take turns on one device. Undo takes back your last move, and an unfinished game is saved if you leave the page.

Nim Game skills

  • Strategic thinking
  • Binary numbers and the nim-sum
  • Spotting winning and losing positions

Level: Ages 7 and up

Tips for Nim

Find the nim-sum without binary: split each row into 4s, 2s and 1s (7 is 4 + 2 + 1, 5 is 4 + 1). Pair up equal parts across the rows. If every part has a partner, the position is losing for the player about to move.

With rows of 3, 4 and 5, the first player can win: 3 = 2 + 1, 4 = 4 and 5 = 4 + 1, so the 2 has no partner. Take 2 from the row of 3 to leave 1, 4 and 5, where every part pairs up.

With rows of 1, 3, 5 and 7 every part already pairs up, so the second player wins with perfect play. Choose Red to go second against Hard.

In Last loses, play the normal strategy until your move would leave only rows of one stick. Then leave an odd number of single sticks instead.

Nim Game questions and answers

How do you play Nim?

Players take turns removing any number of sticks from a single row. In normal play, the player who takes the last stick wins. In misère play (Last loses), the player who takes the last stick loses.

What is the winning strategy for Nim?

Use the nim-sum. Write each row size in binary and add them without carrying (exclusive or). If the nim-sum is not 0, there is always a move that makes it 0, and that’s the move to play. A player who always leaves a nim-sum of 0 can’t lose.

Who wins Nim with 1, 3, 5 and 7?

The second player, with perfect play. The nim-sum of 1, 3, 5 and 7 is 0, so whatever the first player does, the second player can reply to bring it back to 0.

What is misère Nim?

Misère Nim is the version where taking the last stick loses. The strategy is the same as normal Nim until the end: when your move would leave only rows of one stick, leave an odd number of them.

Is Nim a math game?

Yes. Nim is the starting point of combinatorial game theory, the branch of mathematics that studies games like it. Its strategy uses binary numbers, and the Sprague–Grundy theorem shows that many other games can be played as if they were Nim.