Nim

Turn: You

Select stones from one row, then press Take

Category
Board
Players
1
Controls
Tap
Type
Solved game
Loads
Instant

Controls

Tap stonesSelect any number from a single row.
TakeConfirm your move.
New gameReset the rows.
Next up

More games

About this game

Nim gives you several rows of stones. On your turn you take as many as you like from a single row, and the player who takes the last stone wins. It looks like a game of instinct and is in fact completely solved mathematics, which is exactly what makes it interesting.

The solution involves a piece of arithmetic almost nobody would guess: write each row's count in binary and combine them with exclusive-or. If the result is zero, the position is losing for whoever moves next. Nim is the foundation of an entire branch of game theory, and every other similar game reduces to it.

Tips & strategy

Look for symmetry. If you can leave two rows with equal counts and nothing else, you win: whatever your opponent takes from one row, you take the same from the other, and you will inevitably take the last stone.

Learn the losing positions. Two equal rows, or the classic one-two-three arrangement, are traps for whoever must move. Steering the game into one of those shapes and handing it over is how strong play works.

The real rule is the binary one. Convert each row count to binary, exclusive-or them together, and aim to leave a total of zero. It sounds abstract but with three or four small rows you can do it in your head with practice.

Take a whole row when it helps. Beginners take one stone at a time out of caution, but clearing an entire row is often exactly the move that produces a balanced, losing position for your opponent.

Questions

Who wins, the player who takes the last stone?

Yes, in this version taking the final stone wins. Some variants reverse that, which changes the strategy entirely.

Is there a guaranteed winning strategy?

Yes. Nim is completely solved, and whoever is in a winning position can always force the win with correct play.

What is the binary trick?

Write each row count in binary and combine them with exclusive-or. Aim to leave the total at zero after your move.

Can I take from more than one row?

No, only from a single row per turn, but you can take as many from it as you like.

Do I need to download anything?

No. Nim runs entirely inside this page, so it starts the moment the page opens. There is nothing to download, no plugin, and no account to create.