Skip to content
kawu

Nim Strategy: The Nim-Sum

Nim has a complete recipe. Once you can compute the nim-sum in your head you will never lose a position you should win. New here? Read the rules first.

1. Compute the nim-sum

Write the heap sizes in binary and XOR them: in each column, an odd number of 1s gives 1, an even number gives 0. Heaps 3, 4, 5 give 2; heaps 1, 2, 3 give 0.

2. Zero means lost

If the nim-sum is 0 on your turn, every move hands your opponent a winning position. Make a small, harmless-looking move and hope for a mistake.

3. Make it zero

If the nim-sum is not 0, there's always a heap you can shrink to make it zero. Find a heap whose size XOR the nim-sum is smaller than the heap, and reduce it to that value. From 3, 4, 5 (sum 2): 3 ⊕ 2 = 1, so take two from the heap of 3.

4. The misère twist

Play exactly as in normal Nim until your move would leave only heaps of one. Then leave an odd number of single counters instead of an even one, so the opponent is forced to take the last.

5. Spot zero positions

Two equal heaps have nim-sum zero: mirror the opponent. 1-2-3, 1-4-5, 2-4-6, 1-6-7 and 2-5-7 are zero as well. Recognising them saves the arithmetic.

Frequently asked questions

What is the nim-sum?

Write each heap size in binary and add the columns without carrying (exclusive-or). 3 ⊕ 4 ⊕ 5 = 011 ⊕ 100 ⊕ 101 = 010 = 2. A position with nim-sum zero is lost for the player to move.

Last updated 2026-10-20

Play Nim now →Nim rules