IQ Metrics
IIF Certified Assessment Start IQ Test
IIF Certified Assessment
Puzzles & Brain TrainingWell established

How Many Guesses Does the Mastermind Game Take? Five, Using This Strategy

Any of the 1,296 Mastermind codes can be cracked in five guesses or fewer, starting with 1122. A solver we ran gives the counts, a worked game, and what the game says about IQ.

How Many Guesses Does the Mastermind Game Take? Five, Using This Strategy
Illustration generated for IQ Metrics. No photograph is used. IQ Metrics

What you need to know

  • The Mastermind game has 6 x 6 x 6 x 6 = 1,296 possible codes, and Knuth showed in 1976 that every one can be solved in 5 guesses or fewer. The best first guess is 1122: no answer to it leaves more than 256 codes.
  • Our run of Knuth's rule: 1 code solved in 1 guess, 6 in 2, 62 in 3, 533 in 4 and 694 in 5, none in 6. That is 5,801 guesses, an average of 4.48.
  • Koyama and Lai's optimal strategy averages 5,625 / 1,296 = 4.340 guesses (as Goddard reports it) but can need six in the worst case (per Wikipedia), so the five-guess limit and the best average are different goals.
  • We found no study showing that Mastermind raises IQ. People get better at the game with practice, and brain-training research finds gains mainly on the trained task.

The Mastermind game takes at most five guesses to crack, if you play the right strategy. Donald Knuth showed in 1976 that any of the 1,296 possible codes (4 pegs, 6 colours, repeats allowed) can be solved in 5 guesses or fewer, starting with 1122. Our own run of his rule gives an average of 4.48 guesses, against 4.34, the best average that is possible.

Below: the best first guess, a full game worked step by step, how to play it as a person, and what the game does and does not say about IQ. The counts come from a small solver we wrote and ran for this article.

How many guesses does the Mastermind game take?

Five or fewer, for every one of the 1,296 codes. The code maker hides four pegs chosen from six colours, and colours may repeat, so there are 6 x 6 x 6 x 6 = 1,296 codes. Knuth's 1976 paper in the Journal of Recreational Mathematics proves the five-guess limit with a strategy worked out on a computer.

After each guess the code maker answers with black pegs (right colour, right place) and white pegs (right colour, wrong place). Only 14 answers are possible, because three black and one white cannot happen. Knuth's own example: code 2532 against guess 3523 gives one black and two white.

We ran his rule against all 1,296 codes. One code is solved in 1 guess, 6 in 2, 62 in 3, 533 in 4 and 694 in 5, and none needs a sixth. That is 5,801 guesses in all, an average of 4.48.

What is the best first guess in Mastermind?

The best first guess is two pairs, such as 1122: two colours, two pegs each. Any guess of that pattern makes the biggest group of codes left after any answer as small as possible, 256 of the 1,296, and no other pattern does as well. Knuth used 1122. Here is how the codes split after 1122, by our count:

  • No black, no white: 256 codes. No black, 1 white: 256. One black, no white: 256
  • One black, 1 white: 208. Two black, no white: 114. No black, 2 white: 96
  • One black, 2 white: 36. Two black, 1 white: 32. Three black, no white: 20
  • No black, 3 white: 16. Two black, 2 white: 4. No black, 4 white: 1. Four black: 1 (a win)

Other openers are weaker. After the first answer, the biggest group left is 625 codes for 1111, 317 for 1112, 312 for 1234 and 276 for 1123, against 256 for 1122, by our count. With the same rule, a first guess of 1111, 1112, 1123 or 1234 leaves 312, 8, 4 and 8 codes that need six guesses. Knuth wrote that 1123 nearly works but that one line of play fails, and that 1234 appears impossible to guarantee in five. Our run is not a proof for every strategy, but it matches his note.

What is the best Mastermind strategy?

The best Mastermind strategy depends on the goal. To guarantee a win in five guesses, use Knuth's rule. To win in the fewest guesses on average, use the optimal strategy found by Koyama and Lai in 1993, which averages 5,625 / 1,296 = 4.340 guesses.

Knuth's rule is greedy. After each answer, keep only the codes that still fit every answer so far. Then pick the guess, from all 1,296 codes, that makes the largest remaining group smallest. Goddard (2004) describes the rule this way. Our solver breaks ties in favour of a guess that could itself be the code.

The average-case strategy has a cost. Wikipedia reports that Koyama and Lai's method can need six guesses in the worst case. So the two goals pull apart: Knuth's rule never needs more than five, and theirs wins about 0.14 guesses faster on average, 176 guesses fewer over all 1,296 codes. We could not read the 1993 paper itself.

Five guesses always win. The best average, 4.34, gives that guarantee up.

What does a full game look like?

Take the secret code 2536. Here is the rule played step by step, as checked by our solver:

  • Guess 1, 1122: no black, 1 white. 256 codes still fit
  • Guess 2, 2344: 1 black, 1 white. 42 codes still fit
  • Guess 3, 4514: 1 black, no white. 6 codes still fit
  • Guess 4, 1635: 1 black, 2 white. Only 1 code fits
  • Guess 5, 2536: 4 black. Solved

Guess 4 was not a possible code. It was chosen because each of the six codes left would give it a different answer, so the next guess is certain. A guess that cannot win is sometimes the best one, which is why the rule searches all 1,296 codes.

How to win Mastermind as a human player?

How to win Mastermind by hand? Copy the three habits of the solver. Open with two pairs, such as 1122. Find which colours are in the code before you place them. Make each new guess fit all the answers so far, so that it could still be the code.

You can also write down the colours you have ruled out, so you never reuse one by mistake. We did not find a published average for human players, so we give none. Our Code Breaker game lets you try this: in Classic the computer hides a code of 4 pegs from 6 colours, and you get 10 guesses to find it.

Code Breaker has three levels. Easy uses 4 pegs and 6 colours with no repeats, so 360 codes. Classic uses 4 pegs and 6 colours, so 1,296 codes. Hard uses 5 pegs and 8 colours, so 32,768 codes. It also has a daily code and a Numbers mode with digits, in the style of Bulls and Cows, the older pencil-and-paper game that Mastermind resembles.

Does Mastermind measure or raise IQ?

Not by itself, and we found no study that says it raises IQ. The game needs deduction, testing ideas and keeping clues in mind, skills that reasoning tests also sample. But it is one task, and an IQ test samples many. Our cognitive reflection test guide shows how one puzzle type relates to IQ.

People do improve with play. In two experiments, Best (Memory and Cognition, 1990) found that players got better with continued play, and the gains did not depend on the strategy the study had identified. A 2016 review of brain-training research (Simons and colleagues) found extensive evidence of gains on the trained tasks and little evidence of gains on distantly related tasks or everyday thinking.

We searched PubMed on 16 November 2026 for studies of Mastermind and intelligence and found none. A 2011 paper in PLoS Biology uses the game to teach scientific reasoning, but it does not test IQ. See also our other puzzle guides on the 15 puzzle, the Monty Hall problem and Einstein's riddle.

Method, 16 November 2026: we read Knuth's 1976 paper and Goddard's 2004 paper in full and the abstracts of Best (1990), Strom and Barolo (2011) and Simons and colleagues (2016). Every count above comes from a solver we wrote and ran, and the file is kept with this article. We did not read Koyama and Lai (1993); its average is quoted from Goddard, and the six-guess worst case from Wikipedia. Mastermind is a trademark. Knuth's paper names Invicta Plastics Ltd as the maker of the game, and we use the name only to describe the game.
Your own number

Where would your own score land?

Puzzles train one skill. For a score that samples reasoning, memory and speed together, take the IQ Metrics test.

Find your IQ score now! →
Secure & encryptedInstant results10–20 minutes

To see how a score maps to a rank, use our IQ tools or take the IQ Metrics test.

Common questions

How many guesses does the Mastermind game take?

At most five, with Knuth's 1976 strategy. All 1,296 codes (4 pegs, 6 colours, repeats allowed) can be cracked in 5 guesses or fewer. Our solver run solves one code in 1 guess, 6 in 2, 62 in 3, 533 in 4 and 694 in 5, an average of about 4.48.

What is the best first guess in Mastermind?

1122. After it, no answer leaves more than 256 of the 1,296 codes. With the same rule, first guesses of 1111, 1112, 1123 and 1234 leave some codes that need six guesses, and Knuth noted 1234 appears unable to guarantee a win in five.

What is the average number of guesses in Mastermind?

The best possible average is 5,625 / 1,296, about 4.340 guesses (Koyama and Lai, 1993, as Goddard reports it). Knuth's five-guess rule averages about 4.48 in our run. We found no published average for human players.

Does playing Mastermind raise your IQ?

We found no study showing that it does. Players improve with practice (Best, 1990), but brain-training research finds gains mainly on the trained task and little on distant tasks or everyday thinking (Simons et al., 2016).

Sources for this story

  1. Knuth DE. The Computer as Master Mind. Journal of Recreational Mathematics 9(1):1-6 (1976-77); whole text read 16 November 2026 — Baywood Publishing
  2. Goddard W. Mastermind Revisited (2004), which states the Koyama and Lai average of 5,625 / 1,296 and describes Knuth's rule; whole paper read — University of Natal and Clemson University
  3. Best JB. Knowledge acquisition and strategic action in Mastermind problems. Memory and Cognition 18(1):54-64 (1990), doi 10.3758/bf03202646; abstract read — Memory and Cognition
  4. Simons DJ et al. Do Brain-Training Programs Work? Psychological Science in the Public Interest 17(3):103-186 (2016), doi 10.1177/1529100616661983; abstract read — SAGE
  5. IQ Metrics solver run, 16 November 2026: all 1,296 codes, first guess 1122 and Knuth's minimax rule; the counts, the first-guess groups and the worked game — IQ Metrics

Corrections: spotted an error? Email corrections@iqmetrics.org and we will update this story and note the change here.

Share this story

Know someone who keeps seeing this number quoted without the scale it was measured on? Send it to them — it takes one tap.

Filed under#fluid reasoning#working memory#brain training#study quality

Read the research.
Then find your own number.

Our IIF-certified assessment reports your score with its scale, percentile and confidence range — and a breakdown of the cognitive domains behind it.

Start IQ Test →
Secure & encryptedInstant results10–20 minutes