Skip to content
اردو
PZL: Puzzle & Brain

Mastermind

PuzzleSoloMedium~5 min

Ready to play · free

Crack the secret colour code in ten guesses. Also Bulls and Cows, a mode where the computer solves your code, a daily code and two players.

Rate this game

Be one of the first to rate it.

Game info

Developer
PlayNest Studio
Released
Last updated
Platforms
Browser, Android, iPhone, PC
Players
1 or 2 players on one screen
Average play time
~5 min per round
Languages
English, Urdu
Controls
Keyboard or mouse on computers, touch on phones and tablets
01

How to play

  1. Pick a mode and tap colours to fill the row, then press Guess.
  2. A black peg is a right colour in the right place. A white peg is a right colour in the wrong place.
  3. Use every clue to throw out codes that cannot be right. The Hint button gives a guess that fits all clues so far.
  4. Crack the code before the guesses run out. In Bulls and Cows the code is four different digits.
02

Controls

Keyboard & mouse

Click
Pick a colour or select a hole
123
Place a colour by number
Backspace
Remove the last peg
Enter
Submit the guess
←→
Move between holes
H
Hint

Touch

Tap a colour
Place it in the next hole
Tap a hole
Select it to replace
Guess button
Submit the row
Bulb button
Get a hint
03

About

Crack the secret colour code in ten guesses. Mastermind gives you black pegs for the right colour in the right place and white pegs for the right colour in the wrong place. Play the classic 4 pegs and 6 colours, bigger variants, a daily code, Bulls and Cows with digits, two players on one device, or make a code and watch Knuth's algorithm solve it.Also known as Code Breaker, Codebreaker, Bulls and Cows, Cows and Bulls, Mastermind online, Mastermind game, Super Mastermind, Moo.

04

Tips & tricks

  • Open with two colours in pairs, such as red red blue blue.
  • After that, only play guesses that could still be the code given every clue so far.
  • Find out which colours are in the code first, then work out their holes.
  • Watch the computer solve your code to see Knuth's five-guess method at work.

Mastermind: complete guide

Mastermind is the classic code-breaking game: the computer hides a row of coloured pegs and you have ten guesses to crack it, using black and white pegs as clues. Play Mastermind online free here with the classic 4 pegs and 6 colours, bigger 5 peg and 8 colour games, repeats and blanks on or off, a daily code, the number version called Bulls and Cows, a two-player pass-and-play mode, and a mode where you make the code and the computer cracks it with Knuth's five-guess algorithm, with every step explained.

How to play Mastermind online

One side is the code maker and the other is the code breaker. The code maker chooses a secret row of coloured pegs. In the classic game that is four pegs, each one of six colours, and a colour may appear more than once. The code breaker has ten guesses. After each guess the code maker answers with a few small pins that say how close the guess was, and the code breaker uses those answers to narrow the possibilities until the code is found or the guesses run out.

Here the computer is the code maker when you play the Classic or Daily mode. Tap a colour to drop it into the next hole of the current row, tap a hole to select it and replace its colour, and press Guess when the row is full. The row moves up into the board with its black and white pins next to it, and you start the next one.

  • Pick Classic, Daily code, Bulls and Cows, Computer cracks yours, or Two players.
  • Fill the row with your guess and press Guess.
  • Read the pins: black and white tell you how close you are.
  • Use every clue to rule out codes that cannot be right, then guess again.
  • Crack the code before you run out of guesses.

Black and white pegs: what the clues mean

A black peg means one of your pegs has the right colour in the right hole. A white peg means one of your pegs has a colour that is in the code, but in a different hole. No peg means that colour is not in the code, or you already used up all the copies it has. The pins are always shown black first, then white, then empty, and their position says nothing about which hole they refer to. A guess is a win when all four pins are black.

Repeated colours need care. The code RRBG has two reds. If you guess RRRR you get two black pegs (the two reds in the right holes) and no white pegs, because the code has no more reds for the other two guesses to match. If you guess GGGG you get one black peg for the green in the last hole and no white pegs. Each peg of the code can be matched only once. That counting rule is exactly what makes repeated colours a harder puzzle than a code with all different colours.

Mastermind game modes

Classic: the computer makes a random code and you have ten guesses (twelve in the bigger variants). Your wins, average number of guesses and best game are saved.

Daily code: a classic code that is the same for everyone today. Crack it in as few guesses as you can and compare with friends.

Bulls and Cows: the same game with digits. The code is four different digits from 0 to 9. A bull is a right digit in the right place, a cow is a right digit in the wrong place. See the Bulls and Cows section below.

Computer cracks yours: you make the secret code and the computer, using Knuth's algorithm, tries to find it. You press Next guess (or Auto play) and read an explanation of why it chose each guess.

Two players: pass and play on one device. Player 1 makes a code, locks it, and hands over the device. Player 2 tries to crack it. Then the roles swap, and the player who needed fewer guesses wins.

Options: pegs, colours, repeats and blanks

Before a Classic, Computer cracks yours or Two players game you can change the rules. Use 4 or 5 pegs and 6 or 8 colours. Turn repeats off to make every colour in the code different, which shrinks the code count and makes the puzzle gentler. Turn blanks on to allow an empty hole as one more option, which makes the game harder. The start screen shows how many possible codes there are, and the number of guesses grows to twelve for the bigger variants.

For scale: the classic game has 6 x 6 x 6 x 6 = 1,296 possible codes. With 5 pegs and 8 colours (sometimes sold as Super Mastermind) there are 32,768. With repeats off in the classic game there are only 360. If a colour is hard to tell apart on your screen, turn on Symbols on pegs and every colour also gets its own shape.

Mastermind strategy: how to win

Open with two colours in pairs, such as red red blue blue. A first guess with four different colours feels more adventurous, but the two-pair opening splits the 1,296 codes into groups that are on average smaller, which is why it is also the opening Donald Knuth used.

After that, play consistent guesses: pick a guess that could still be the secret code given every clue so far. If the guess is not the code, at least it is still a candidate, and every answer then tells you something. The Hint button does exactly this for you: it fills the row with a random code that fits all previous clues. If you can follow the hint and say why it fits, you are learning the game.

Test colours before positions. Early on, focus on discovering which colours are in the code. Later, move pegs around to find their holes. Keep a note of what each clue ruled out: if a guess scored nothing, those colours are out for good, which helps a lot.

Be careful with duplicates. If a guess with two reds scores one white, you know there is at least one red but you do not yet know there are two. Guesses that mix a new colour with a repeated old one are an easy way to count how many of each colour the code has.

Knuth's five-guess algorithm, explained

In 1977 Donald Knuth showed that the classic game can always be won in five guesses or fewer. His method has a clear idea behind it: after every guess, keep the list of codes that are still possible, then pick the next guess that makes the worst case as small as possible.

The steps are: first, guess 1122 (two colours, two of each). Second, look at the pins you get and throw away every code that would have given a different pin result against that guess. Third, for each candidate next guess, imagine every possible answer and count how many codes would remain. The size of the biggest group is the worst case for that guess. Pick the guess with the smallest worst case, and if there is a tie prefer a guess that could itself be the code, because it has a chance to win outright. Repeat until the pins are all black.

Run the algorithm on all 1,296 codes and the result is: 1 code is cracked on the first guess, 6 on the second, 62 on the third, 533 on the fourth and the remaining 694 on the fifth. The average is about 4.48 guesses, and no code ever needs six. We test this in our code: every one of the 1,296 secrets is cracked in five guesses or fewer.

Let the computer crack your code

Choose Computer cracks yours, make any code (or press Random code) and lock it in. The computer now plays as the code breaker. Each time you press Next guess it computes the guess Knuth's method would choose. A panel under the board explains the step: how many codes still fit the clues and what the worst case would be after this guess. On the classic game it never needs more than five guesses, which you can watch for yourself. For the bigger variants the computer looks at a sample of the remaining codes instead of every one, so it is quick, but the 5-guess promise only applies to the classic 4-peg, 6-colour game with repeats.

This is the fastest way to learn better play. Try to predict its next guess, then compare. You will notice it often plays a guess that looks strange but cuts the number of remaining codes dramatically.

Bulls and Cows number game

Bulls and Cows is the pen-and-paper ancestor of Mastermind. The secret is four different digits, so there are 10 x 9 x 8 x 7 = 5,040 possible codes. After each guess you hear how many bulls (right digit, right place) and how many cows (right digit, wrong place). Here the board shows digits instead of coloured pegs and writes the bulls and cows next to each guess. With best play the number can always be found in seven guesses or fewer, and the average is around five. You have ten guesses here.

It plays like Mastermind with a number keypad, and it is also known as Cows and Bulls or Moo. Good Bulls and Cows play uses exactly the same tools: a smart opening such as 1234 (or 0123), counting what each clue rules out, and consistent guesses once you have enough information.

Daily code and statistics

The daily code is the same for every player on a given day, so you can compare results. Your best guess count for the day is saved. Statistics for Classic and Bulls and Cows show games played, games won, your average guesses per win and your best result. They stay in your browser.

Mastermind and Wordle: the same idea

If you enjoy Wordle you already know the Mastermind loop. In both games you guess, get feedback about right-place and wrong-place pieces, and cut down the space of possible answers with logic. Mastermind uses coloured pegs and four holes; Wordle uses letters. The consistent-guess idea carries over directly, and the minimax thinking behind Knuth's algorithm is also how solvers rate Wordle openings.

A short history of Mastermind

Mastermind was designed in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert, and released by the British toy company Invicta Plastics in the early 1970s. It was inspired by the older pen-and-paper game Bulls and Cows and went on to sell tens of millions of copies. Its fixed, tiny rules (a few pegs, a few colours, a handful of guesses) hide a surprisingly deep search problem, which is why computer scientists have studied it for decades.

05

Mastermind FAQ

Is Mastermind free to play?
Yes. Mastermind is completely free on PlayNest. There is nothing to buy and no account to create.
Do I need to download Mastermind?
No. Mastermind runs in your web browser, so you can start playing straight away on Chrome, Safari, Edge or Firefox.
Can I play Mastermind on my phone?
Yes. Mastermind works on Android phones, iPhones, tablets and computers, with touch and keyboard controls.
How many players can play Mastermind?
It is a single-player game.
How long does a game of Mastermind take?
A round takes about 5 minutes. It is rated medium and sits in our Puzzle & Brain collection.
What is Mastermind?
Mastermind is a code-breaking board game. One side hides a row of coloured pegs and the other has a limited number of guesses to find it, with black and white pegs as clues.
What do the black and white pegs mean?
A black peg means a right colour in the right place. A white peg means a right colour in the wrong place. The pins do not say which hole they refer to.
Can I play Mastermind online for free?
Yes. Mastermind on PlayNest is free in your browser, with no sign-up and no download.
How many guesses do I get?
Ten in the classic 4 peg, 6 colour game. The bigger variants (5 pegs, 8 colours or blanks) give twelve.
What is the best first guess in Mastermind?
Two colours in pairs, such as red red blue blue (1122). It is the opening used in Knuth's five-guess algorithm for the classic game.
What is Knuth's algorithm?
It is a method by Donald Knuth that always cracks the classic Mastermind code in five guesses or fewer. After each guess it keeps all codes still possible and picks the next guess that makes the worst-case leftover as small as possible.
Can the computer solve my code?
Yes. Choose Computer cracks yours, make a code and press Next guess. It plays Knuth's strategy and explains each step. In the classic game it never needs more than five guesses.
What are Bulls and Cows?
Bulls and Cows is the number version of the game. The code is four different digits. A bull is a right digit in the right place and a cow is a right digit in the wrong place.
Is Bulls and Cows the same as Mastermind?
It is the same idea with digits instead of colours and with no repeated digits. Mastermind was inspired by Bulls and Cows.
How many possible codes are there?
1,296 in the classic game, 360 if repeats are off, 5,040 in Bulls and Cows and 32,768 with 5 pegs and 8 colours.
Can I play Mastermind with two players?
Yes. Choose Two players. One of you makes a code, hides it and passes the device. Then you swap roles, and the player who cracked the other's code in fewer guesses wins.
Can I get a hint?
Yes. The Hint button puts a guess that fits every clue so far into the row. Use it to check your own reasoning.
Is there a daily Mastermind?
Yes. The daily code is the same for everyone each day. Your best guess count for the day is saved.
Can I use blanks or repeated colours?
Yes. In the options you can turn repeats off for a gentler game and blanks on for a harder one. You can also use 5 pegs and 8 colours.
Is there a colour-blind option?
Yes. Turn on Symbols on pegs and every colour also gets its own shape.
06

You might also like

More Puzzle & Brain