Nim
Take turns removing stones. Whoever takes the last stone wins. There is a secret that always wins. Can you find it?
Play now — no sign-up · Play Nim free
The rules, in four steps.
- Three variants: 21 (one pile of 21, take 1–3), Limit (one pile, take up to the number shown) and Piles (several piles, any number from one pile).
- On your turn, take at least one stone, all from the same pile.
- Whoever takes the last stone wins. There are no draws.
- Online games are rated: the variant is drawn at random, and each player has 60 seconds for the whole game.
The oldest maths duel
Nim is one of the oldest strategy games. Two players take turns removing stones, and whoever takes the last stone wins. There is no luck in it: every position is either winning or losing for the player about to move, and the game is about knowing which.
Schools know it as the 21 game. It trains counting back, division with a remainder and, in the version with several piles, binary numbers. On Duelto it is played against a bot with three levels, by two players on one screen, or online against a real opponent for rating.
Three ways to play
- 21
- One pile of 21 stones. Each move takes 1, 2 or 3. The classic starting point, from age 8.
- Limit
- One pile of 15 to 30 stones and a limit of 3 to 5, shown on screen. Each move takes from 1 up to the limit. The idea of 21, with numbers that change every game.
- Piles
- Three or four piles of up to 7 stones. A move takes any number of stones, all from one pile. This is classic Nim, and the hardest of the three.
How to get better
- Start from the end. If a move takes up to 3 and 4 stones are left, you lose whatever you do. Work out what that means for 5, 6 and 7.
- Then go one step further back: which number would you like to leave your opponent, so they face the same trouble?
- Against the bot, use the Hint button when you are stuck. After a loss, the game shows the move where the win slipped away.
- In Piles the trick for one pile no longer works. Write each pile in binary and look for a pattern.
- Beat Hard in 21 first, then in Limit, then in Piles.
Questions
Is there a way to always win at Nim?
From most positions, yes: the player who knows the secret can force a win. Charles Bouton published the full solution for classic Nim in 1901. The bot on Hard plays it perfectly, but every bot game starts from a position you can win, so beating Hard means you have found the secret too.
Is Nim good for learning maths?
Yes. The secret of the 21 game is a lesson in division with a remainder, and classic Nim leads to binary numbers. Teachers have used it for a long time because children want to find the trick by themselves.
How do online games work?
Online games are rated. The variant and the stones are drawn at random, and so is the player who moves first, so nobody can prepare one position. Each player has 60 seconds for the whole game; whoever runs out loses.
Can I play without an account?
Yes. Against the bot and with two players on one screen, Nim needs no account. Online games and the rating need a free one.
Is it free?
Yes. Every game on Duelto is free to play, with no ads inside the game and nothing to buy.
Do I need to download anything?
No. Duelto runs in the browser on a phone, tablet or computer. A free account, made with an email address, is all you need.
Can children play?
Duelto is open from age 8. Accounts for players under 13 are activated by a parent through the confirmation email, and run with extra restrictions.
Other games on Duelto
- RPS Board — Arrange 14 pieces, capture the flag. Rock-paper-scissors decides every fight.
- Classic RPS — Pure rock-paper-scissors — best of 5. Read your opponent, win the duel.
- BattleShield — Shield, reload, or fire — at the same time as your opponent. A 10-second showdown each round.
- Tic-Tac-Toe — The timeless 3-in-a-row duel — quick, sharp, and now ranked.