← Back to blog

The Hidden Geometry of Tic-Tac-Toe (Why There Are Exactly 8 Winning Lines)

The math behind why corners beat edges, and how everything changes in 3D Β· 9 min read

Take a tic-tac-toe board. Count the ways to win. Three rows, three columns, two diagonals β€” that's eight.

Why eight, though? Could it be any other number? What if the board were different β€” a 4Γ—4 grid, a 3D cube, a hexagonal shape? How does the geometry of the board determine the strategy of the game?

These aren't just abstract questions. The geometry of the winning lines is the strategy. Once you understand how lines are counted on different board shapes, you understand why centers are stronger than edges, why bigger boards play differently, and why some variants of tic-tac-toe are wildly out of balance while others are perfectly fair.

The eight winning lines, counted formally

For a standard 3Γ—3 board, the winning lines are exactly eight:

Add them up: 3 + 3 + 2 = 8.

You might wonder why there are only two diagonals. On a 3Γ—3 board, a diagonal of length 3 has to start at a corner, and there are only four corners β€” but each diagonal connects two corners, so there are only 4/2 = 2 distinct diagonals. The main diagonal runs top-left to bottom-right; the anti-diagonal runs top-right to bottom-left.

Why "almost any line" doesn't count

A winning line in tic-tac-toe has three specific properties:

  1. Three cells in a straight line. Three of your cells anywhere β€” say, three corners β€” doesn't count if they don't form a line.
  2. Connected (adjacent in the line direction). The cells must be next to each other along the line, not scattered with gaps.
  3. On the board. Lines that extend past the edge of the board don't count.

If you relaxed any of these conditions, you'd have many more "winning configurations." Three of the four corners is geometrically a triangle, but it's not a winning configuration because the cells don't sit on a line. The pattern X _ _ X _ _ X _ _ on a 3Γ—3 read column-by-column is also not a line because the cells aren't adjacent in line direction. The strict rules give us exactly the 8 lines we know.

The general formula: lines on an nΓ—n board

For an nΓ—n board where you need k cells in a row to win, the line count follows a simple formula:

The reasoning: on each row of n cells, the number of length-k segments is (n βˆ’ k + 1) β€” because each segment is identified by its starting column, and the starting column can range from 1 to (n βˆ’ k + 1). Multiply by n rows. The diagonals are slightly more subtle because they vary in length depending on which "anti-row" they sit on, but the count works out to (n βˆ’ k + 1)Β² in each of the two diagonal directions.

Let's verify with examples:

BoardkCalculationTotal lines
3Γ—333 + 3 + 2(1) = 88
4Γ—444 + 4 + 2(1) = 1010
4Γ—434(2) + 4(2) + 2(4) = 2424
5Γ—545(2) + 5(2) + 2(4) = 2828
5Γ—555 + 5 + 2(1) = 1212

Notice how dramatically the line count changes when you lower the win-length. On a 4Γ—4 board needing 4 in a row, there are 10 winning lines. On the same board needing only 3 in a row, there are 24 β€” more than twice as many. That's because shorter segments fit into the same board many more times.

Why this matters for game balance

The ratio of winning lines to total cells gives you a rough sense of how "attack-heavy" a game variant is. More lines per cell means more opportunities to threaten, which means more aggressive games and more wins by the first player.

VariantLinesCellsRatioCharacter
3Γ—3, need 3890.89Balanced β€” solved as a draw
4Γ—4, need 410160.63Defensive, lots of draws
4Γ—4, need 324161.5Heavily attack-favored; first player essentially always wins
5Γ—5, need 428251.12Aggressive but still drawable
5Γ—5, need 512250.48Very defensive, draws common

The general pattern: lower line ratios mean more drawish, defensive games. Higher ratios mean attack-favored, winnable games. The 3Γ—3 game sits in a sweet spot β€” interesting but solvable to a draw β€” which is part of why it's been the standard format for centuries. The variants on either side either get boring (too defensive) or unfair (too attack-favored, first player dominates).

The cell-value heatmap

Within any board, not every cell is equal. A cell's strategic value is determined by how many winning lines pass through it. Each line that passes through a cell is one more way that cell can contribute to a win β€” and one more line a player must defend if the opponent occupies that cell.

On a 3Γ—3 board needing 3 in a row, the line-count for each cell is:

Number of winning lines through each cell (3Γ—3, k=3). Center: 4. Corners: 3. Edges: 2.

This is why classic tic-tac-toe strategy says "center beats corner beats edge." The strategic ranking of cells comes directly from this geometry. There's no judgment call involved β€” it's just counting.

The same calculation applies to bigger boards. On a 4Γ—4 board needing 4 in a row, the four innermost cells (the 2Γ—2 block in the middle) each sit on 4 lines, the four corners sit on 3, and the eight edge cells sit on 2. The strategic value comes from the same geometric source.

3D tic-tac-toe (and beyond)

Things get especially interesting when you move to three dimensions. A 3Γ—3Γ—3 board has 27 cells arranged in a cube. The winning lines now include not just horizontal rows, vertical columns, and 2D diagonals, but also:

The total number of winning lines on a 3Γ—3Γ—3 board is 49. Compared to 8 lines on the flat 3Γ—3, that's a six-fold increase in attacking opportunities. And the cell-value distribution gets even more skewed β€” the center cell of the 3D cube is part of 13 lines (the three axes through it, six 2D diagonals through its three planes, and four space diagonals). Owning the center of a 3D board is enormously powerful.

Unsurprisingly, given the line-to-cell ratio (49 / 27 β‰ˆ 1.8), 3D tic-tac-toe is heavily attack-favored. In fact, it's been proven that the first player wins with perfect play β€” a result first established by Oren Patashnik in 1980 using an exhaustive computer-assisted proof.

4D tic-tac-toe β€” yes, this is a real thing mathematicians have studied β€” has even more lines and even more imbalance. Higher-dimensional variants get strategically interesting in odd ways, with new types of geometric patterns emerging. But they also become impossible to play physically (no one can see a 4D board), so they remain mostly mathematical curiosities.

The deeper insight

The most important takeaway is that geometry is strategy. The shape of the board β€” the number of cells, the win-length, the dimensionality β€” determines the playability and the balance of any tic-tac-toe-style game. A game designer working on a new variant doesn't have to playtest dozens of versions to find a balanced one; they can compute the line-to-cell ratio and predict the game's character in advance.

This is part of why mathematicians find tic-tac-toe and its variants fascinating. The game is small enough to be fully analyzed and varied enough to demonstrate genuinely interesting patterns. Every time you adjust the board, you get a different game with different mathematics underneath. And the strategic feel of each variant follows directly from the geometry, in a way you can predict on paper before ever placing a single mark.

The next time you look at a tic-tac-toe board, try counting the lines that pass through each cell. You'll find yourself instinctively reaching for the cells with the highest counts. That instinct isn't intuition β€” it's geometry, applied automatically by your brain.


Switch between 3Γ—3, 4Γ—4, and 5Γ—5 modes on our Big Board game and notice how the geometry changes the feel of the game.

Play Big Board β†’

Related reading