Mastermind

Crack the secret four-shade code from the feedback clues.

How to play Mastermind

Pick a shade, fill the slot, then read the pegs

A secret code of four pegs is chosen from six distinct shades. Pick shades to fill a guess row. After each guess you get feedback: a filled peg means a shade is correct and in the right spot; an open peg means a correct shade in the wrong spot. Use the clues to crack the code in ten tries.

How to crack the code

Every guess buys you two kinds of information. A filled peg means one of your shades is exactly right: correct colour, correct slot. An open peg means a shade is in the code but you have put it in the wrong place. Crucially, the feedback never tells you which of your pegs earned which mark, so the whole skill is designing guesses that let you deduce the rest. The efficient approach is to split the puzzle into two questions, which shades are in the code and where each one belongs, and to answer them in that order rather than all at once. Ten rows sounds generous, and it is: players who treat each row as an attempt to win outright burn through them and lose, while players who treat the early rows as questions rarely need more than six.

A worked opening

Watch the two-phase method run. Guess one: four pegs of the first shade. Feedback, one filled peg, so the code holds exactly one of it. Guess two: four of the second shade. Nothing comes back, and that shade leaves the puzzle entirely. Guess three: four of the third shade, two pegs, so two of those. Three rows in, your counts total three, meaning exactly one slot is still unaccounted for, and one more single-shade probe settles it. The moment the counts reach four, stop probing: any shades you never tested are ruled out for free. Now the arrangement phase begins with the game three-quarters solved and six rows still on the table.

Rearranging has its own discipline: change one thing at a time. Swap exactly two pegs between guesses and watch the filled count. Up means one of the swapped pair went home, down means you broke a match, unchanged means both or neither were placed right, and every one of those answers eliminates arrangements in bulk.

Rules of thumb that save guesses

The mathematics of five guesses

With six shades and four slots, repeats allowed, there are 1296 possible codes, and each guess sorts all of them into bins by the feedback it would produce. Only fourteen distinct feedback answers exist, so a well-chosen guess splits the surviving codes into small piles no matter which answer comes back, while a lazy guess leaves one giant pile intact. That is the entire theory of the game in two sentences, and it is why Donald Knuth was able to prove in 1977 that a code-breaker playing the pile-minimizing strategy wins in five guesses at worst, opening with two pairs. Later analysis trimmed the average to about 4.34 guesses. Ten tries leaves you room for a whole wasted experiment and the win besides.

The story behind Mastermind

Mastermind in its familiar peg-and-shield form was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert, and the big toy companies turned it down repeatedly before Invicta Plastics, a small firm in Leicester, England, took the gamble. It became one of the defining games of the 1970s, with tens of millions of sets sold before the decade was out. The idea was not brand new even then: it is a coloured-peg descendant of Bulls and Cows, a paper-and-pencil digit game played for generations, physicalized into a hidden code behind a screen and feedback delivered in small black and white key pegs. And the famous box art, a distinguished bearded man with a woman standing behind him, starred two locals: a Leicester hairdresser named Bill Woodward and a computing student named Cecilia Fung, who posed again for anniversary editions decades later.

Mastermind leaderboard

Top scores. Log in to compete.

  1. Loading leaderboard…

Mastermind: frequently asked questions

Can a shade repeat in the code?

Yes. The secret code may contain the same shade more than once, which the feedback pegs account for.

How do I win the leaderboard?

Solve the code in the fewest guesses. Your best (lowest) winning guess count is saved.

What is the difference between a filled peg and an open peg?

A filled peg means one of your chosen shades is both the right colour and in the right position. An open peg means a shade is present in the secret code but sits in the wrong slot. The pegs are unordered, so they never point to which guess peg is which.

How do I work out how many of one shade the code contains?

Fill an entire guess row with that single shade. The number of feedback pegs you get back equals the count of that shade in the hidden code, since every match of that colour is reported. Repeat for a few shades to map the code's contents.

Does the feedback tell me which peg is correct?

No, and that is the heart of the puzzle. You learn how many shades are right and how many are merely present, but not where. Isolating positions takes careful guesses that change only one peg at a time so you can attribute the difference.

What does a guess that scores nothing tell me?

A surprising amount. Zero pegs means none of those shades appear anywhere in the code, so a single-shade row that comes back empty erases that shade from the puzzle, and a mixed row that comes back empty can rule out four shades at once. Some of the most valuable guesses in the game score nothing.

In how few guesses can Mastermind always be solved?

For the standard four pegs and six shades, Donald Knuth showed in 1977 that an optimal strategy always wins in at most five guesses. Human players rarely play perfectly, but the result shows the code is far more crackable than ten tries suggests.

Should I keep trying new shades late in the game?

No. Once you have identified which shades the code uses and how many of each, introducing untested colours wastes a precious guess. Switch to rearranging the known shades and use each remaining try to pin down positions.

Is Mastermind free to play?

Yes. Mastermind is completely free on Inkplay, with no download, no sign-up, and no in-game purchases. Open the page and play instantly on desktop or mobile.

Can I play Mastermind unblocked?

Yes. Mastermind runs entirely in your browser with no download, install, or plugins, so it loads instantly and keeps working even on school or work networks where bigger game sites get blocked.

More games to play

In the mood for more? Try 2048, Memory Match, Lights Out, Minesweeper, or browse all puzzle games and the full games list on Inkplay. Mastermind also appears in Brain Games.

This game has been removed

It's no longer available. Try one of our other games instead.

Browse games