Code Breaker: crack the hidden color code

Guess the secret color code with the help of black and white pegs.

Loading puzzle…
Code Breaker game cover

A classic code-breaking game

Code Breaker is the classic game of deduction behind the board game Mastermind. A secret code of colors is hidden from you. After each guess you get black and white pegs that say how close you are, and you narrow the possibilities until the code cracks.

It takes a minute to learn and rewards clear thinking. Play the Mastermind-style game online free, with a new code every round.

A classic game of deduction

Code breaking games are older than computers. Players once played a pencil-and-paper version called Bulls and Cows, where one person thinks of a number and the other guesses, getting clues after each try. In the 1970s the idea became a famous board game with colored pegs. The version here uses four pegs and six colors, with repeats allowed.

In 1977 the computer scientist Donald Knuth showed that, in this classic setup, any secret code can be found in at most five guesses with the right strategy.

How to play here

Choose colors for the four slots of your guess and submit it. Feedback pegs tell you how close you are: one kind of peg for each color in the right place, and another for each right color in the wrong place. The feedback pegs do not tell you which slots they refer to; working that out is the puzzle.

A step-by-step strategy

  1. Open with two colors. A first guess like red, red, blue, blue tells you about two colors at once.
  2. Keep every clue consistent. Each new guess should be a code that could still be the answer given everything you have learned.
  3. Change one thing at a time when you are close. Swapping two pegs or replacing one color shows exactly what that change did.
  4. Use elimination. If a color scores nothing, it is gone from every slot. Use it as a “blank” to test other colors.
  5. Count the colors first, then the positions. Once the total number of hits tells you which four colors are in the code, focus on the order.

Why play Code Breaker?

It is a pure logic game with a clear goal: crack the code in as few guesses as you can. Four or five guesses is excellent play. If you enjoy deduction from clues, try Minesweeper or Mosaic.

How to play Code Breaker

  1. The computer hides a code of four colored pegs. Colors can repeat.
  2. Make a guess by filling a row with four colors.
  3. A black peg means one of your pegs is the right color in the right place.
  4. A white peg means one of your pegs is the right color in the wrong place.
  5. Crack the code within ten guesses to win.

Code Breaker tips

Open with two colors

A first guess like red, red, blue, blue tells you about two colors at once and keeps the next steps simple.

Keep every clue consistent

Each new guess should be a code that could still be correct given all the feedback so far. That is how strong players finish in five moves or fewer.

Change one thing at a time

When you are close, swap a single peg between guesses so you know exactly which change moved the score.

Frequently asked questions

Is Code Breaker the same as Mastermind?

It uses the classic Mastermind rules of colored pegs and black and white feedback. Mastermind is a trademark of its respective owner, and MindedGames is not affiliated with it.

What is the fewest number of guesses needed?

With four pegs and six colors, any code can be broken in five guesses or fewer using the right strategy.

Do the feedback pegs show which position is right?

No. They only tell you how many pegs are right, not which ones. Working out which ones is the puzzle.