Curious Minds

Clear answers to science and history questions

How Does Stockfish Work? Engine Explained

· 6 min read · Science

Stockfish works by combining a highly optimized alpha-beta search of the game tree with a neural network that evaluates positions, all running on ordinary CPU hardware. It does not "think" like a human; it generates legal moves, searches ahead, and uses the network's judgment to decide which resulting positions are promising.

Background: What Stockfish Is and Where It Came From

Stockfish is a free, open-source chess engine. It began around 2008 as a fork of the open-source engine Glaurung, and since then it has been developed by a large community of programmers who contribute improvements through public testing. The engine is distributed under the GPL, and its source code is available for anyone to inspect, compile, or modify.

An engine is not a chess-playing robot or a human-like AI. It is a program that takes a position and returns a move and an evaluation. Stockfish has no graphical interface of its own; it communicates through a text protocol called UCI (Universal Chess Interface), which chess GUIs, websites, and analysis tools use to send positions and receive moves. This separation is why the same engine can run inside many different programs.

Stockfish is consistently one of the strongest engines in the world in standard chess, and it also supports Chess960 and other variants. Its strength comes from decades of accumulated engineering: efficient move generation, sophisticated pruning, and a well-trained evaluation function.

How the Search Works

At its core, Stockfish performs a search over the tree of possible moves. The basic algorithm is alpha-beta pruning, a refinement of minimax that skips branches that cannot affect the final decision. In practice, the engine uses many enhancements to search deeper and more selectively:

  • Iterative deepening: it searches to depth 1, then depth 2, and so on, reusing information from shallower searches to order moves well.
  • Transposition table: a large hash table that stores results of previously searched positions, since different move orders can reach the same position.
  • Move ordering: trying likely-good moves first (captures, checks, killer moves) makes pruning far more effective.
  • Pruning and reductions: techniques like null-move pruning, late move reductions, and futility pruning cut away lines that are unlikely to matter.
  • Quiescence search: at the leaves of the main search, it extends only tactical moves (captures and checks) to avoid the horizon effect, where the engine misjudges a position because a capture happens just beyond its search depth.

The result is that Stockfish can examine many millions of positions per second on a modern multi-core CPU, reaching depths of 30 plies or more in middlegame positions, depending on time controls.

Evaluation: The Neural Network

Search alone is not enough; the engine needs a way to score positions that are not terminal. Historically, Stockfish used a handcrafted evaluation function with terms for material, pawn structure, king safety, mobility, and so on. Since 2020, it has used a neural network called NNUE (Efficiently Updatable Neural Network).

NNUE is a small neural network designed to run efficiently on CPUs. It takes features describing the position (such as piece placement and material) and outputs a single score in centipawns, where 100 centipawns is roughly equivalent to one pawn. The "efficiently updatable" part means that when a move is made, the network's internal state can be updated incrementally rather than recomputed from scratch, which is crucial for speed during search.

The network is trained on millions of positions with known game outcomes or engine evaluations. Training uses supervised learning: the network learns to predict a target score from the position features. The exact training data and architecture have evolved, but the principle is consistent: a compact network that approximates a strong evaluation function while remaining fast enough for deep search.

This hybrid approach—deep search plus a learned evaluation—is what makes Stockfish so strong. The search explores concrete lines, while the network provides a nuanced static assessment that guides the search.

How Stockfish Is Used in Practice

Most people interact with Stockfish through a chess GUI or a website. The typical workflow is:

  1. Load a position into the GUI (from a game, a FEN string, or by playing moves).
  2. Set the engine's search limits: time per move, depth, or nodes.
  3. Start analysis; the engine returns a principal variation (best line) and an evaluation.
  4. Review the suggested moves and the evaluation score to understand the position.

Stockfish can also play games against humans or other engines. In engine-vs-engine matches, time controls and hardware matter greatly; results are often reported with Elo ratings, though these are relative to the pool of opponents and the conditions.

For analysis, a common mistake is to treat the engine's top move as the only correct move. In many positions, several moves are nearly equal, and the engine's evaluation can fluctuate. The principal variation shows one line, not all reasonable plans. Human judgment is still needed to interpret why a move is good.

Strengths, Limitations, and Common Misconceptions

Stockfish is extremely strong tactically and positionally in standard chess. However, it is not infallible. Its evaluation is based on patterns learned from data and search; it can misevaluate closed positions or long-term strategic plans that require understanding beyond its horizon. It also has no concept of practical difficulty for a human opponent—it may choose a move that is objectively best but practically hard to handle.

A common misconception is that Stockfish "sees" all possible moves. It prunes heavily and relies on heuristics; it can miss deep resources, especially under fast time controls. Another misconception is that a higher depth number always means a better move; depth is not directly comparable across different positions or hardware, and the engine's own evaluation can change as it searches deeper.

Stockfish is also not designed for cheating in online games. Using it in rated play violates fair-play rules on most platforms. It is a tool for analysis, training, and research.

Hardware and Performance Factors

Stockfish runs on CPUs and scales with the number of cores and threads. More threads allow parallel search, which can increase depth and strength, though with diminishing returns. Hash size (the transposition table) also matters: too small a hash causes more re-searches; too large can be wasteful but is rarely harmful on modern machines.

Because NNUE is CPU-optimized, Stockfish does not require a GPU. This makes it accessible on ordinary laptops and servers. Performance is often measured in nodes per second (nps), but nps alone does not determine strength; search efficiency and evaluation quality matter more.

Time management is another factor. The engine allocates time across moves based on the position's complexity and the remaining clock. Poor time management can cause it to play too fast or flag in extreme cases, though this is rare in normal use.

Frequently Asked Questions

Is Stockfish free to use?

Yes. Stockfish is open-source software released under the GPL. You can download it, use it, and redistribute it under the terms of that license. Many GUIs and websites bundle it.

Does Stockfish use artificial intelligence?

It uses machine learning for its evaluation network (NNUE), which is a form of AI. However, it is not a general-purpose AI; it is a specialized chess engine with a narrow task.

Can Stockfish run on a phone?

Yes. There are mobile apps and ports that run Stockfish on Android and iOS. Performance depends on the device's CPU and available memory.

Why does Stockfish sometimes give different moves on different runs?

If the engine is set to a fixed depth and single-threaded, results are deterministic. With multiple threads or time-based limits, timing and thread scheduling can cause slight variations in search and final move choice.

Is a higher depth always stronger?

Not necessarily. Depth is a search limit, but strength depends on evaluation quality and pruning. A deeper search with poor pruning can be weaker than a shallower, well-tuned search. In practice, more depth usually helps, but it is not a guarantee.

What is NNUE?

NNUE stands for Efficiently Updatable Neural Network. It is a compact neural network used by Stockfish for position evaluation, designed to update incrementally during search so it remains fast on CPUs.

In this article
  1. Background: What Stockfish Is and Where It Came From
  2. How the Search Works
  3. Evaluation: The Neural Network
  4. How Stockfish Is Used in Practice
  5. Strengths, Limitations, and Common Misconceptions
  6. Hardware and Performance Factors
  7. Frequently Asked Questions