Veena Games
Browse

Popular

Casino

More

Code-Breaking Games

Mastermind: Can You Always Win in Five Guesses?

Standard Mastermind can be forced within five guesses, but only because Knuth’s algorithm treats each clue as a search-space split.

Manit Kaushal Founder · Veena Games 7 min read

Yes. In standard four-peg, six-colour Mastermind, you can force a win within five guesses: Knuth’s published algorithm proves it for all 1,296 possible codes. The catch is that the method is a solver’s mastermind strategy, not the way most humans think over a cup of tea.

The popular mastermind five guesses claim is about the classic rules: repeats allowed, four positions, six colours, and feedback that reports exact matches and right-colour-wrong-place matches. Change those rules and the number changes. Add more colours, ban repeats, change the length, or give different clues, and you need a separate result.

The useful lesson is not that five is magic. It is that Mastermind becomes manageable when you stop asking, “What feels likely?” and start asking, “Which guess cuts the remaining possibilities hardest?” Knuth’s algorithm is famous because it turns that question into a repeatable rule.

Can you always win Mastermind in five guesses?

You can always win standard Mastermind in five guesses if you use a complete five-move decision method. The best-known one is Donald Knuth’s 1977 algorithm. It covers all 1,296 possible secret codes in the classic four-position, six-colour game with repeated colours allowed.

The claim has limits. It is not “any sensible player will solve it in five”. It is not “the first four guesses are fixed”. It is not “you only ever guess codes that could still be the answer”. Knuth’s method is a branching tree: each guess depends on the feedback from the previous guess, and some guesses are used because they split the possibilities well, even when they cannot themselves be the secret.

The usual opening in Knuth’s published method is 1122: two pegs of one colour and two pegs of another. On a lettered board, think AABB. From there, every possible feedback result points to a smaller set of codes. The algorithm then chooses a next guess that makes the worst remaining pile as small as possible.

For normal play, five guesses is therefore a ceiling, not a promise about your unaided instincts. A human player can often win well within ten guesses with disciplined elimination, but can also drift badly by chasing attractive-looking answers. The five-guess result belongs to a precise solver rule applied without mistakes.

What figure should a player trust, and where does it come from?

Trust the worst-case number first: five guesses. It is the figure that answers winnability. Averages are interesting, but an average can hide a few stubborn codes that take longer.

No estimate is needed for the main claim. The code count is exact, and the five-guess guarantee is a published result for a fixed rule set. If a page gives a different number without stating the rules, it is probably mixing variants.

Which one mechanic makes the game hard enough to need a plan?

The hard mechanic is anonymous feedback. Mastermind does not tell you which peg was right. It only tells you how many pegs are exact matches and how many are correct colours in the wrong positions.

Suppose you guess AABB and receive one exact match and one misplaced match. You know that two parts of your guess have hit something useful. You do not know whether the exact match was the first A, the second A, the first B, or the second B. You also do not know which colour caused the misplaced match. Duplicates make that uncertainty worse, because the same colour can be involved more than once.

For four pegs, there are 14 possible feedback scores. That sounds generous until you remember there are 1,296 possible hidden codes before the first guess. Each clue is therefore a sorting signal. It throws every possible code into a bucket according to the answer it would have produced.

This is the single reason the Knuth algorithm works. It does not guess by resemblance to the secret. It guesses by partitioning. A strong guess is one that prevents any feedback result from leaving a large, awkward bucket behind. Weak guesses may look plausible, but they let too many possible secrets survive together.

What does a solid Mastermind strategy actually look like?

  1. Start with a structured split. AABB is a good human-friendly opening, and it matches the shape of Knuth’s 1122 start. You learn about two colours at once and you get information about duplicates.
  2. Write down what survives. After each clue, keep only the codes that would have produced exactly that same feedback against your guess. If a code would have given a different clue, it is impossible. Cross it out mentally or on paper.
  3. Judge a guess by its worst case. For each possible next guess, imagine scoring it against every code still alive. Group those codes by feedback result. The largest group is the danger: if you get that clue, all those codes remain.
  4. Prefer the guess with the smallest largest group. This is the core minimax idea behind the Knuth algorithm. A guess can be valuable even if it cannot be the answer, because it may cut the remaining set more evenly than any candidate answer would.
  5. Only chase the answer when the list is small. Early in the game, information beats hope. Later, when two or three codes remain, direct guessing is fine because every clue almost settles the matter.
  6. Respect duplicate colours. Many errors come from treating one white peg as proof that a colour appears once. It proves a match of that type, not the full count unless the rest of the clue forces it.

How does Mastermind compare with Bulls and Cows, and why do people mention the Knuth algorithm?

Mastermind and Bulls and Cows are close cousins: both reward elimination, and both punish lazy reading of feedback. The exact five-guess number belongs to standard Mastermind, so do not transfer it without checking the rules.

QuestionMastermindBulls and CowsWhy it matters
What is hidden?Four positions chosen from six colours, with repeats allowed in the standard result.Usually a sequence of digits; the exact code space depends on the chosen rule set.The size of the search space controls how strong the guarantee can be.
What does feedback mean?Exact colour and position, plus correct colour in the wrong position.Bulls are exact hits; cows are right symbols in wrong positions.The logic is similar enough that the same elimination habit carries across.
Is the feedback anonymous?Yes. It gives counts, not peg identities.Yes. It gives counts, not digit identities.This is why both games need disciplined deduction rather than simple matching.
What trusted win claim applies?Knuth’s published algorithm solves all 1,296 standard codes within five guesses.The Mastermind five-guess claim does not automatically apply.A figure is only useful when it matches the exact rules being played.
Why mention Knuth?His algorithm is the classic example of minimax search in this game.Players often borrow the same search-space thinking.The name points to a method: reduce the worst remaining case.

People mention the Knuth algorithm because it is clear, finite, and a little rude to intuition. It sometimes chooses a guess that cannot be right, purely because the answer to that guess will be more useful than a plausible-looking candidate.

Frequently asked questions

Final thoughts

The uncomfortable move in Mastermind is the one that feels least like guessing. You may have two tempting candidate codes sitting there, both neat, both possible, and the best move may be a third code you already know cannot win. That is where the game becomes interesting.

If you are playing by feel, you will tend to ask whether a code looks close. A solver asks what the reply will do to the whole remaining set. That question is colder, but it is also kinder: it stops you wasting three turns learning the same fact in slightly different ways.

For a human player, you do not need to run Knuth’s full tree in your head. Keep one habit. After every clue, ask which possibilities would have given exactly that clue. If the answer is “I am not sure”, slow down. Most Mastermind mistakes are not bold risks; they are bookkeeping errors.

Five guesses is a lovely benchmark, but ten guesses gives room to think. Use the room. Make a boring information move when the board asks for it. The satisfying win is often the one where the last peg feels inevitable before you place it.

Keep reading

More on Code-Breaking Games