How to play Mastermind: rules, pins explained and a winning strategy

  • Players1 player, or challenge a friend
  • Time2–10 minutes a puzzle
  • DevicesAny phone or computer
Play Mastermind

Mastermind is a classic code-breaking puzzle. There's a secret code of four pegs, each red, yellow, green or blue, and you have ten guesses to find it. After every guess you get pins that tell you how many pegs you got right, but not which ones.

Our version has a daily code (the same for everyone, so you can compare), an unlimited practice mode, and challenges: set your own secret code and send it to a friend as a link.

The rules and the pins

The code is four pegs from four colours. Colours can repeat, so blue blue green blue is a valid code. That makes 4 × 4 × 4 × 4 = 256 possible codes.

After each guess, you get up to four pins:

  • A black pin means one of your pegs is the right colour in the right spot.
  • A white pin means one of your pegs is the right colour, but in the wrong spot.
  • No pin for a peg means that colour isn't in the code, or the code doesn't have any more of it.

Two things trip people up. The pins come in no particular order, so the first pin doesn't mean your first peg. And each peg in the secret code is only counted once. If the code has one red and you guessed two reds, you'll get one pin for red, not two.

A worked example

Here's a real game, start to finish. The secret code is green, blue, yellow, blue.

  1. Guess: red, red, yellow, green. Pins: 1 black, 1 white. Two of the pegs are the right colour, and one of those is in the right spot, but the pins don't say which. Even so, only 46 of the 256 codes fit.
  2. Guess: blue, blue, green, yellow. Pins: 1 black, 3 white. Four pins means all four of these colours are in the code. The code is some arrangement of blue, blue, green and yellow. Only one peg is in the right spot. That leaves 4 possible codes.
  3. Guess: yellow, blue, blue, green. Pins: 1 black, 3 white. This guess was chosen because each of the four remaining codes would give it a different set of pins. Only one code matches this answer: green, blue, yellow, blue.
  4. Guess: green, blue, yellow, blue. Four black pins. Solved in four.

Notice the third guess. It wasn't trying to be the answer. It was picked to split the remaining codes apart, so that whatever the pins said, the next guess would be certain.

A strategy that always works

With four colours and four pegs, any code can be solved in four guesses or fewer with the right method. Ten guesses is plenty of room; the challenge is doing it in as few as possible.

  • Open with a pair and two singles, like red, red, yellow, green. Of all the first guesses, this kind splits the 256 codes into the most groups, and leaves at most 46 codes whatever the pins say. Four of one colour (red, red, red, red) is the weakest opener: it can leave over 100 codes.
  • Write down what you know. After each guess, note which colours are in, which are out, and how many of each. Most mistakes come from forgetting what an earlier guess ruled out.
  • Every guess has to fit every earlier answer. Before you submit, check it against each previous guess: would it have given those same pins? If not, it can't be the code.
  • Use colours you've ruled out as filler. Once you know red isn't in the code, a red peg is a blank. Putting red in two spots lets you test the other two spots cleanly.
  • When few codes are left, split them. If four or five codes are still possible, the best guess is the one that gives each of them different pins, even if it can't be the answer itself.

The daily code, stats and sharing

There's a new daily code at midnight, your local time. Your guesses are saved as you go, and your stats keep your wins, streak and how many guesses each win took. With a free Thorstein Games account, your stats follow you to your other devices.

When you finish, Share result copies your pins only, like Wordle, never the colours, so it doesn't spoil the code for anyone else.

Practice mode gives you a fresh random code as often as you like, without touching your stats. It's a good place to try the strategy above.

Challenging a friend

Tap the share button at the top to make a challenge: choose your own secret code, pick how many guesses your friend gets (10 to 15), add your name and send the link. The code is scrambled in the link, so your friend can't peek at it.

A good challenge code isn't necessarily a strange one. Codes with repeats, like yellow yellow yellow blue, tend to catch out players who assume all four colours are different.

Questions

What do the black and white pins mean in Mastermind?

A black pin is a right colour in the right spot. A white pin is a right colour in the wrong spot. The pins aren't in any order, so they don't tell you which peg they're about.

Can colours repeat in the code?

Yes. Any arrangement is possible, so there are 256 codes.

What's the best first guess?

A pair and two singles, like red, red, yellow, green. It splits the possible codes into the most groups, and with good follow-up guesses any code can be solved in four or fewer.

Can I play more than once a day?

Yes. Practice mode gives you a new random code every game. Practice games don't count toward your daily stats.

HomeGuidesFAQAbout