Counting the Games

Nine squares, at most nine moves - How big can the game really be? Let's break it down step by step.

What "9!" Actually Means

You'll sometimes see tic tac toe math written with a "9!" symbol. That's called a factorial, and it just means "multiply this number by every whole number below it, down to 1." So 9! = 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 362,880. That's how many ways you could fill all nine squares in order, if nobody ever won early.

Why the Real Number Is Smaller

Real games don't fill every square. The moment a player completes a line, the game stops. Once you remove all the "extra" sequences that would have kept going after a win, the true count of distinct games drops to 255,168.

Removing Mirror Images

The board also looks the same when you rotate it or flip it like a mirror. A win in the top row is really the same shape as a win in the bottom row, just turned around. Treat those matching games as one game, and the count collapses to 26,830 essentially different games, and just 765 essentially different board positions.

QuantityCount
Move sequences (ignoring early wins)362,880
Distinct complete games255,168
Games up to rotation/reflection26,830
Reachable board positions5,478
Positions up to symmetry765
Winning lines on the board8

Why Perfect Play Always Draws

Tic tac toe is a solved game. That means computers, and patient humans, have checked every possible position. The verdict: neither player can force a win if the other one defends correctly.

Every Opening Leads to a Draw

Every opening move for X leads to a draw if O responds correctly. And every O reply holds the draw if X keeps playing correctly after that. That's why our Hard mode can promise something unusual: it will never lose. If you also play perfectly, every game ends level.

  • Correct defense stops every attack before it becomes a real threat.
  • Correct offense can't force a mistake out of a flawless opponent.
  • The result is always a draw between two players who never slip up.

What "Solved" Really Means

Because the outcome is fixed in advance, tic tac toe is called a solved game: with perfect play the result - Here, a draw - Is decided before the first move, as long as nobody blunders. Chess may well be solvable in the same sense, but nobody has proven it, because chess has far too many positions to check by hand or even by computer.

The First-Move Advantage, Quantified

Draw or not, going first matters a lot in practice.

The Win, Loss and Draw Breakdown

Across all 255,168 possible games:

  • 131,184 (51.4%) end in a win for X, the first player;
  • 77,904 (30.5%) end in a win for O;
  • 46,080 (18.1%) end in a draw.

Why X Has the Edge

Against imperfect opponents, X wins nearly twice as often as O. X gets five marks to O's four, and always gets to threaten first. This is why our 2 player mode alternates the starting player every round. Over a long match, fairness means trading that advantage back and forth.

The Magic Square Connection

Here's the most elegant fact in tic tac toe mathematics.

A Square Where Everything Sums to 15

Take the 3×3 magic square below. It's a special arrangement of the numbers 1 to 9 where every row, column and diagonal adds up to the same total: 15.

276
951
438

Turning Numbers Into a Tic Tac Toe Game

Now imagine a new game: two players pick numbers 1 to 9 in turn, and whoever collects three numbers that sum to 15 first wins. That game is exactly tic tac toe wearing a disguise. Each number stands for a square, and each sum-to-15 triple stands for a winning line.

Why the Center Square Is So Strong

This trick also explains why the center square matters so much, and it's the secret behind Numerical Tic Tac Toe too. The number 5 sits inside four of the eight sum-to-15 triples, the same way the center square sits inside four of the eight winning lines on the board.

How the Unbeatable AI Works: Minimax

Our Hard mode doesn't use tricks or lookup tables. It runs minimax, the foundational algorithm of game theory, live in your browser.

The Four Steps of Minimax

  1. From the current position, the computer imagines every legal move it could make.
  2. For each, it imagines every reply you could make, then every counter-reply, all the way to every possible end of the game.
  3. Each finished game gets a score: +1 if the computer wins, −1 if you win, 0 for a draw (nearer wins score slightly higher, so it prefers quick kills and slow losses).
  4. Working backwards, it assumes you will always pick the move best for you (lowering its score) while it picks moves best for it (raising its score). That's where the name "minimax" comes from.

Why a Phone Can Solve It Instantly

Tic tac toe is tiny by computer standards. There are at most 9! move sequences, and most branches get cut short once a game ends early. That means a phone can search the entire game in milliseconds.

The result is what mathematicians call provably perfect play, meaning it can be proven, not just observed, that minimax never makes a mistake. In practice that means minimax never picks a move that leads to a forced loss: a position where the other side is guaranteed to win no matter what happens next. Since tic tac toe is already proven to end in a draw with correct play, never losing means minimax never loses at all.

Bigger games like chess and Go use the same core idea, but they add two shortcuts tic tac toe doesn't need:

  • Depth limits: stopping the search after a set number of moves instead of playing every game to the end.
  • Evaluation functions: a scoring guess for positions the search didn't fully finish, used to judge them anyway.

Tic tac toe is small enough to skip both shortcuts and search all the way to the bottom, every single time.

Try It Yourself

Want to feel what perfect play is like from the other side? Challenge the minimax opponent, or study the human strategy guide first and see how close to perfect you can get.