Last updated: August 19, 2026
Remove objects from one heap per turn and plan the final move. Learn Nim rules, calculate the nim-sum with XOR, and practice a proven winning strategy.
Loading game...
Charles L. Bouton published a complete mathematical theory of Nim in 1901. He proved that players can classify any normal-play position by taking the bitwise exclusive OR, or XOR, of its heap sizes. A zero nim-sum marks a position that loses against correct play; a nonzero nim-sum gives the next player a route to zero. This makes Nim a rare game with a compact, proven decision method rather than a rule of thumb. Play free against the computer, test the XOR strategy, and learn why one careful removal can control the result.
A beginner faces heaps of 1 and 2. The nim-sum is 1 XOR 2, which equals 3, so the position offers a winning move. The player removes one object from the heap of 2, leaving 1 and 1. The opponent must clear one heap. The player then clears the last heap and wins. Matching the heaps gave the opponent a zero nim-sum.
The heaps contain 3, 4, and 5 objects. Their nim-sum equals 2. Test reducing 3 to 1: 1 XOR 4 XOR 5 equals 0, so remove two objects from the first heap. If the opponent changes 5 to 2, the new position 1, 4, 2 has nim-sum 7. The player calculates again rather than guessing and looks for another move to zero.
Only heaps of 1, 1, and 1 remain. Their XOR equals 1, so the player to move holds a winning position. The player removes one entire heap, leaving two single heaps. The opponent takes one, and the player takes the last object to win. If only two single heaps had remained at the start, the player to move would have lost against correct play.
Play Nim online for free against a computer in your browser. Choose a heap, remove one or more objects, and try to take the final object under normal-play rules. No board setup or download is required. Start with small heaps to see the zero nim-sum pattern, then raise the difficulty and practice binary XOR on larger positions. Every turn gives you a fresh mathematical decision.
| Version | Difficulty | Players | Typical Time |
|---|---|---|---|
| Small Heaps | Easy | 1 vs computer | 2 to 4 min |
| Standard Nim | Medium | 1 vs computer | 3 to 6 min |
| Large Heaps | Hard | 1 vs computer | 4 to 8 min |
The nim-sum is the bitwise XOR of all heap sizes. Write the sizes in binary and combine each column without carrying. A column returns 1 when it contains an odd number of 1 digits and 0 otherwise.
In standard normal-play Nim, a zero nim-sum means the player to move loses if the opponent responds correctly. An opponent can still make a mistake later, so continue checking every resulting position.
Charles L. Bouton published the complete theory in 1901. His paper connected winning and losing positions to what later terminology calls the nim-sum, calculated through binary XOR.
Under normal play, the player to move wins when an odd number of single-object heaps remain and loses when an even number remain, assuming correct responses. Their XOR equals 1 for odd parity and 0 for even parity.
Nim pairs one plain move rule with a complete mathematical strategy. Remove objects from one heap, aim to take the last object, and use XOR to separate winning positions from losing ones. Bouton's 1901 result gives you a concrete target: leave a zero nim-sum after each turn. Start a free browser game, calculate the heaps, and test the proof against the computer.