Rules, strategy & FAQ

Choose Difficulty

Select a difficulty level to begin

Easy

4 colors · 4 pegs · 10 attempts · duplicates off

Beginner

Medium

6 colors · 4 pegs · 10 attempts · duplicates on

Standard

Hard

6 colors · 5 pegs · 8 attempts · duplicates on

Expert

Impossible

8 colors · 5 pegs · 6 attempts · duplicates on

Nightmare

Set the Secret Code

Player 1: Choose 4 colors. Player 2 won't see this!

Build Your Code

Click the pegs below to assign colors, then confirm.

Medium
vs CPU
Attempt 1/10
0:00
Secret Code
Hidden until game ends
Guess Board

Play Mastermind Online for Free

Mastermind is a code-breaking game for two players. One player, the codemaker, hides a secret code made of coloured pegs. The other, the codebreaker, tries to work out the code in a limited number of guesses, using a few clues after each guess.

This free version lets you play against the computer, which sets a random code, or against a friend on the same device. It has four difficulty levels and runs in your browser with no download or sign-up, on desktop, tablet and phone.

The modern game was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. It is based on an older pencil-and-paper game called Bulls and Cows.

Mastermind Rules

  1. The codemaker sets a secret code. It is a row of coloured pegs. At lower levels, each colour can be used only once. At higher levels, colours can repeat.
  2. The codebreaker makes a guess. They fill a row with coloured pegs and submit it.
  3. The codemaker gives feedback. A red peg means one of your pegs has the right colour in the right place. A white peg means one of your pegs has a colour that is in the code but in a different place. No peg means that colour is not used.
  4. Keep guessing. Use the feedback to work out the code. You win by getting all pegs right before you run out of attempts.

The feedback tells you how many pegs are right, but not which ones. That is what makes the puzzle.

How to Play Here

  1. Choose a mode. vs Computer means you break the computer's code. vs Human means one player sets the code and the other guesses.
  2. Choose a difficulty and press Start Game. In vs Human mode, Player 1 then builds the secret code while Player 2 looks away, and confirms it.
  3. Build a guess. Click a colour in the palette, then click a peg in the current row. Or press 1 to 8 on your keyboard to pick a colour. Use the small cross on a peg to clear it.
  4. Submit. Press the tick button on the row, or press Enter. The clue pegs appear next to your guess.

The top bar shows the difficulty, the mode, your attempt number and a timer. The side panel shows your colours, the number of exact and partial matches in your last guess, and a legend. In vs Human mode, a score panel counts the rounds each player has won, and the Swap Roles button lets players change sides. Restart asks you to confirm before starting over, and Menu returns to the start screen.

Difficulty Levels

Colours, pegs, attempts and possible codes for each level
LevelColoursPegsAttemptsRepeatsPossible codes
Easy4410No24
Medium6410Yes1,296
Hard658Yes7,776
Impossible856Yes32,768

Medium matches the classic game: four pegs, six colours, and repeated colours allowed, which gives 1,296 possible codes. Impossible has far more codes and only six attempts, so you need to use every clue.

Mastermind Strategy and Tips

Start with a guess that uses repeated colours

On the classic four-peg, six-colour game, famous solver Donald Knuth showed that opening with two pairs, such as red, red, blue, blue, lets you solve every code in five guesses or fewer. A good first guess tests two colours at once.

Use every clue

After each guess, list what the feedback rules out. If you get no pegs at all, none of those colours is in the code, and you can drop them for the rest of the game.

Make every guess possible

Try to guess a code that could still be correct given all the feedback so far. This keeps you moving toward a win and avoids wasted guesses.

Separate colour from position

First work out which colours are in the code, then work out where they go. Moving one peg at a time between guesses shows you exactly what changed.

Remember how repeats work

On Medium and above, a colour can appear more than once. A guess with three reds will only score as many pegs as there are reds in the code, so use duplicates to count them.

Set a tricky code as codemaker

In vs Human mode, a code with a repeated colour is harder to crack than four different colours, and more so on the higher levels.

Mastermind FAQ

Is Mastermind free to play here?

Yes. There is nothing to download and no account to create.

What do the red and white pegs mean?

A red peg means a correct colour in the correct position. A white peg means a correct colour in the wrong position.

Do the clue pegs show which of my pegs are right?

No. The pegs only count the matches. You have to work out which pegs they refer to.

Can colours repeat in the code?

Not on Easy. On Medium, Hard and Impossible, a colour can appear more than once.

How many guesses do I get?

10 on Easy and Medium, 8 on Hard and 6 on Impossible.

Can I play Mastermind with a friend?

Yes. Choose vs Human and take turns on the same device. One player sets the code and the other guesses. There is no online matchmaking.

What keyboard shortcuts are there?

Press the number keys 1 to 8 to choose a colour, and press Enter to submit your guess.

Does Mastermind work on a phone?

Yes. Tap a colour and then a peg. The board resizes to fit your screen.

More Free Logic Games

If you enjoy cracking codes and deduction, try Wordle, Knights and Knaves, Sudoku, Binary Puzzle, Battleships or Magic Square. All of them play free in your browser.

Browse all Venjex games