← All Games

Code Breaker

How to play Code Breaker

Code Breaker is a free puzzle game by Extensive Harmony that you play in your web browser. Crack the secret colour code in as few guesses as you can. The classic colour code logic game. It works on desktop and mobile — no download, no sign-up.

Goal

Guess the secret code of coloured pegs. After each guess you see how close you are.

Controls

  • Tap a colour / 1 to 8 – Add a peg to your guess
  • Backspace – Remove the last peg
  • Enter / Check – Submit the guess

Tips

A black dot means right colour in the right place. A white dot means right colour in the wrong place. Dots are not in peg order. Easy codes never repeat a colour; Medium and Hard can.

How a game of Code Breaker goes

The computer picks a secret code. You build a guess by tapping colours (or typing their numbers), press Check, and get dots that tell you how close you are. You have 10 guesses on Easy and Medium and 12 on Hard. The size of the puzzle grows fast: Easy has 360 possible codes, Medium 1,296 and Hard 32,768, so each level needs a sharper plan.

Code Breaker strategy

Every guess is a question, and the dots are the answer. Good players choose guesses that ask the most useful question, not just the code they think is most likely.

  1. Find the colours first. On Easy, guess 1-2-3-4 and then 3-4-5-6. The two answers tell you which colours are in the code.
  2. Then find the places. Move one colour at a time. If a black dot turns white, you know that colour was in the right place before.
  3. Every guess must fit all earlier answers. Before you check, test your guess against each earlier row: would it have produced the same dots?
  4. Use the numbers. Every colour has a number, so you can type guesses with keys 1 to 8 and press Enter.
  5. On Medium and Hard, use pairs. A guess like 1-1-2-2 tells you how many 1s and 2s the code has.

Reading the dots

  • Black dot: one peg is the right colour in the right place.
  • White dot: one peg is the right colour in the wrong place.
  • No dot: one peg's colour is not in the code, or the code has fewer of that colour.
  • The dots are not in the same order as the pegs, so they do not tell you which peg they belong to.

Patterns to recognise

  • No dots at all. The best bad news there is: every colour in that guess is out of the code. Cross them all off.
  • Black plus white equals the colours found. On Easy, if a guess gets 4 dots in total, you have all four colours and only the order is left. There are just 24 possible orders, usually found in two or three more guesses.
  • All white. Every colour is right, but none is in place. Each colour must move to a different position, which rules out a lot of orders.
  • One colour swapped. If you change one peg and the black count drops by one, the old peg was right. If it rises by one, the new peg is right. Change one thing at a time to learn exactly this.

How many guesses does it really take?

We let a computer play with the game's own scoring code (tools/code-breaker-strategy.js) and the plain method above: a fixed first guess (1-2-3-4 on Easy, 1-1-2-2 on Medium, 1-1-2-2-3 on Hard), then always the first code that fits every answer so far. No clever look-ahead, just rule 3 of the strategy list.

LevelPossible codesCodes testedAverage guessesMost guesses neededGuesses allowed
Easy360all 3604.15610
Medium1,296all 1,2965.02810
Hard32,7683,000 random codes6.611112

The guess limit is generous as long as every guess fits the earlier answers: the simple method never ran out on Easy or Medium, and on Hard it cracked all 3,000 test codes, although two of them took 11 of the 12 guesses. Most lost games come from a guess that ignores an earlier row. Knuth's cleverer method, which picks the guess that leaves the fewest possibilities in the worst case, cracks every Medium code in five; the simple method averages about five there but can need eight.

Common mistakes

  • Repeating a ruled-out colour. Keep track of colours that got no dots; using them again wastes a peg.
  • Changing everything at once. When you are close, change one or two pegs per guess so you know which change made the difference.
  • Forgetting repeats on Medium and Hard. A code like 3-3-5-1 is possible. If your colour count doesn't add up, a colour may appear twice.

Did you know?

  • The board game Mastermind was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert, and first produced by the British company Invicta Plastics.
  • Long before that, people played Bulls and Cows with pencil and paper, guessing secret numbers instead of colours.
  • In 1977 the computer scientist Donald Knuth proved that any 4-peg, 6-colour code with repeats can be found in at most five guesses, if each guess is chosen to leave the fewest possibilities in the worst case.

Read the full guide to Code Breaker and Mastermind rules, or try Nonogram and Sudoku.

Frequently asked questions

Is Code Breaker free to play online?

Yes. Code Breaker runs in your web browser for free, with no download, account or sign-up, on a phone or a computer.

How do you play Code Breaker?

The computer hides a code of 4 or 5 coloured pegs. You guess a code, and after each guess you get one black dot for every peg with the right colour in the right place, and one white dot for every right colour in the wrong place. Use the dots to narrow down the code before you run out of guesses.

Is Code Breaker the same as Mastermind?

It follows the same rules as the classic board game Mastermind and its pencil-and-paper ancestor Bulls and Cows. Code Breaker is our own free version that you can play in a browser.

What do Easy, Medium and Hard change?

Easy has 4 pegs and 6 colours with no repeated colours. Medium also has 4 pegs and 6 colours, but colours can repeat. Hard has 5 pegs, 8 colours and repeats, with 12 guesses.

How is the score calculated?

You score 20 points for every guess you had left when you cracked the code, including the winning guess. Harder levels multiply the score. Running out of guesses scores 0.

Is there a strategy that always wins?

Yes. With 4 pegs and 6 colours, Donald Knuth showed in 1977 that every code can be cracked in at most five guesses. You do not need his method to win, but planning each guess to test new information helps a lot.

Keep playing

Read more

How Many Guesses Does Code Breaker Need? Knuth, the Best Opening and Our Test

More Puzzle games

Part of our brain games collection.

New to browser games? See why playing in your browser beats installing apps.

Embed Code Breaker on your website

Teachers, bloggers and site owners can add this game to a page for free. Copy the code below; please keep the credit link.