Nim Game Play the Classic Math Strategy Game Online

Step 1: Choose your opponent, rule and start

0You / Player 1
0Computer

Step 2: Pick sticks from one row, then press Take sticks

© 2004–2026 QuickOnlineTips. This game’s code and design are our own work. You are welcome to use it here for free, but please do not copy, republish or sell it. Terms of use

Help us improve this game

★ Black Friday★ Cyber MondayWeb hosting up to 85% off, checked on each host’s own siteGrab the deals →

About this game

Play the Nim game, one of the oldest strategy games in the world, free online. Sticks are laid out in rows. On your turn, take as many sticks as you like from any one row. In the classic version, whoever is forced to take the last stick loses. Play a friend, or take on a computer that plays perfectly on hard.

Quick answer: Click a stick to select it and every stick to its right in that row, then press Take. You must take at least one stick, from one row only. With “Last stick loses”, leave your opponent the final stick. With “Last stick wins”, grab it yourself.

How to play the Nim game

  1. The classic start has four rows of 1, 3, 5 and 7 sticks.
  2. Players take turns. On your turn, remove one or more sticks from a single row.
  3. In the standard (misère) game, the player who takes the last stick loses. You can switch to “Last stick wins” too.

The secret winning strategy

Nim was completely solved by the mathematician Charles Bouton in 1901. Write each row size in binary and add the columns without carrying (this is called the XOR or nim-sum). If the nim-sum is zero after your move, you are in a winning position, because whatever your opponent does, you can make it zero again.

RowSticksBinary
11001
23011
35101
47111
Nim-sum000

The classic 1-3-5-7 start has a nim-sum of zero, so the player who moves first is at a disadvantage against perfect play. In the “last stick loses” version, play the same way until only rows of one stick remain, then leave an odd number of single sticks.

Nim tips for beginners

  • Pairs cancel out. Two equal rows always have a nim-sum of zero, so mirror your opponent’s moves on them.
  • Count single sticks at the end. In last-stick-loses, you want your opponent to face an odd number of single sticks.
  • Practice on easy first, then switch to hard and see if you can find the winning moves.

Like strategy games? Try dots and boxes, checkers or tic tac toe. For number practice, there is the times tables game.

FAQ

Can I beat the computer on hard?

Yes, if you start from a position with a nim-sum other than zero and never make a mistake. Try “Random rows” and go first.

Is Nim good for teaching math?

Yes. It is a fun way to introduce binary numbers, XOR and game strategy, and kids enjoy trying to beat the computer.

Found this useful? Share it with someone who needs it.

Tech Terms Starter Pack cover

$4.99Free when you subscribe

Get 100 tech terms explained in plain English

8-page PDF on AI, coding, slang and SEO + one tech email a week.

Don’t want emails? Buy the PDF for $4.99 (opens in a new tab)

Sent by email. Unsubscribe anytime. See our privacy policy.

Latest Tech Guides