Mastermind Strategy: How to Crack the Code With Fewer Guesses

Mastermind Strategy: How to Crack the Code With Fewer Guesses

To crack a Mastermind code with fewer guesses, treat every row as an experiment: read the feedback carefully, eliminate codes that contradict earlier clues, and choose guesses that distinguish the remaining possibilities. A useful guess does not always look close to the answer; sometimes its greatest value is what it rules out.

The challenge is learning to separate what you know from what you merely suspect. With a repeatable process, those mysterious colored pegs become a surprisingly readable trail of evidence.

Understand Exactly What the Feedback Means

This guide uses the classic mathematical version of Mastermind: four positions, six available colors, and repeated colors allowed. That creates 6 × 6 × 6 × 6 = 1,296 possible codes. Check your edition’s rules before playing, because variations can change the challenge.

Feedback comes in two types:

  • Exact match: A correct color in the correct position.
  • Color-only match: A correct color in the wrong position.

Traditional descriptions call these black and white hits, although physical editions may use different indicators. Crucially, the feedback gives totals—it does not identify which guessed pegs earned them. Consult Hasbro’s official Mastermind instructions for your edition’s presentation.

Repeated colors require special care. Each occurrence can count only once. If the secret contains one red peg and your guess contains three reds, those three guesses cannot all receive credit for the single red in the secret.

Write feedback as “E” for exact matches and “C” for color-only matches, such as 1E, 2C, so you never confuse feedback colors with code colors.

Start With a Purpose, Not a Favorite Color

A useful opening to learn is AABB: two pegs of one color followed by two of another. The letters simply represent colors.

This is the opening used in Donald Knuth’s five-guess strategy. It belongs to a complete decision-making method, however—not a magic sequence that solves the game by itself.

For a beginner-friendly exercise, try opening with red-red-blue-blue and ask:

  • How many guessed pegs received credit altogether?
  • Were any of those matches exact?
  • Which possible codes now contradict that result?

Avoid automatically following your opener with two pairs of different colors. First, examine the feedback. Your second guess should answer a question raised by the first row, rather than follow a fixed script.

For example, suppose AABB receives no matches. Neither A nor B occurs anywhere in the secret. That is a powerful result, even though the guess looks like a complete miss. This follows directly from the game’s scoring rules.

Keep a Candidate List and Use Every Clue

A candidate is a code that could still be the answer.

Your central task is to reject candidates that would not produce the feedback already recorded. Knuth’s method formalizes this process by maintaining the possibilities consistent with the previous guesses.

You do not need to write out all 1,296 starting codes. Instead, keep a compact notebook with three areas:

| Area | What to record | |---|---| | Guess history | Each guess and its exact feedback | | Confirmed facts | Conclusions that must be true | | Open possibilities | Colors, positions, or complete codes still under consideration |

Be precise with your language. “Red might be in position two” is not the same as “Red must be in position two.”

Before submitting a likely answer, pretend that it is the secret and score every earlier guess against it. If even one result differs from the recorded feedback, that candidate is impossible.

This is also a practical way to resist becoming attached to one attractive theory. For broader advice on that habit, explore Puzzles Arcade’s guide to avoiding tunnel vision in puzzle solving.

Before playing a candidate as your answer, check it against the oldest clue first, then work forward through every row.

Work Through a Small Example

Here is a deliberately simplified practice situation, not a complete game. Suppose earlier clues have narrowed the secret to just three candidates:

  • ABCD
  • ABDC
  • ACBD

Consider guessing ABCD. Applying Mastermind’s scoring rules gives a different result for each possible secret:

| If the secret is… | Feedback for ABCD | |---|---| | ABCD | 4 exact matches | | ABDC | 2 exact, 2 color-only | | ACBD | 2 exact, 2 color-only |

The guess might win immediately, but otherwise it leaves two possibilities.

Now consider the legal test guess ABAD. Scoring it against those same three candidates produces:

| If the secret is… | Feedback for ABAD | |---|---| | ABCD | 3 exact matches | | ABDC | 2 exact, 1 color-only | | ACBD | 2 exact matches |

Every result is different. Although ABAD cannot be the secret in this example, its feedback tells you exactly which remaining candidate is correct.

That does not automatically make it the better choice. Assuming the three candidates are equally likely, both approaches average two additional guesses, including the final answer. The lesson is more specific: a guess can be informative even when it cannot win immediately.

Choose Guesses That Separate Possibilities

When several codes remain, ask:

“Would these candidates give different feedback to my next guess?”

That question is often more productive than “Which code feels most likely?”

As an exercise, imagine six remaining candidates. One proposed guess might divide them into feedback groups of five and one. Another might divide them into groups of two, two, and two. The second guess leaves fewer possibilities in its worst case.

This is the basic intuition behind minimax: choose a guess whose largest possible surviving group is as small as possible.

For casual play, you can approximate this without calculating every legal guess:

  1. Write down several remaining candidates.
  2. Propose a possible next guess.
  3. Score it against those candidates.
  4. Look for repeated feedback results.
  5. Compare it with another proposed guess.

Treat this as a learning exercise, not a requirement to turn every game into homework. Even comparing two options can reveal why one asks a clearer question.

What Knuth’s Five-Guess Strategy Actually Guarantees

Knuth demonstrated that the four-position, six-color game with repeats allowed can always be solved in five guesses or fewer using his complete strategy. His paper, The Computer as Master Mind, explains the method.

In outline:

  1. Start with AABB.
  2. Remove every code inconsistent with the feedback.
  3. Evaluate legal guesses by their largest possible remaining candidate group.
  4. Choose a guess that minimizes that largest group.
  5. Break ties by preferring a remaining candidate, then the first code in a fixed numerical ordering.

The evaluation includes guesses that are no longer possible answers.

The five-guess guarantee depends on following the complete method. Starting with AABB and then improvising does not inherit the guarantee, nor should you assume it applies to versions with different rules.

If you use a solver while practicing, predict its next guess first, then compare how your choice and its choice separate the remaining candidates.

Avoid These Guess-Wasting Habits

Use this checklist whenever a game starts feeling tangled:

  • Reading feedback as positional. One exact match does not identify which position is correct.
  • Forgetting duplicates. Keep repeated-color candidates unless the rules or clues exclude them.
  • Using only the newest row. A possible answer must satisfy every previous response.
  • Repeating a guess. With a fixed secret and accurate feedback, the same guess supplies the same information.
  • Treating “almost right” as solved. Three exact matches still require identifying the remaining color.

These checks follow from Mastermind’s scoring system and its requirement that the hidden code stay fixed during the attempt.

For your next game, focus on one achievable goal: do not submit an intended answer that contradicts an earlier clue. Then practice comparing how well two possible guesses distinguish the surviving codes.

Fewer guesses are satisfying, but understanding why a guess works is the real breakthrough. Stop asking the code to reveal itself through luck; start asking it better questions.

Share: