Game guide · Puzzle

How to crack the code

In a code-breaking game one side hides a row of colours and the other side guesses, with only a few lights to say how close each guess came. It feels like guesswork at first, but every light is a hard fact, and a little bookkeeping turns those facts into the answer. This guide shows you how.

3 min read · Updated · Free, in your browser

AllFun Code Breaker: a steel vault with columns of coloured gem guesses and gold and silver clue lights
AllFun Code BreakerEasy, Classic and Hard modes, a Daily code and a counter of the codes still possible.

What a code-breaking game is

A secret code is a short row of colours, chosen in order. You make a guess of the same length, and you are told two numbers: how many of your colours sit in exactly the right place, and how many are the right colour in the wrong place. You are never told which ones. From these two numbers, guess after guess, you work out the whole row.

Playing on AllFun

AllFun Code Breaker hides the code in a steel vault. Gold lights count gems in the right place; silver lights count right colours in the wrong place. Every gem colour also has its own sign, so you can tell them apart at a glance.

Beside the vault, Codes left shows how many codes still agree with every light you have seen. It is the best teacher in the game: a good guess makes that number fall fast. Hint opens one gem of the secret if you get stuck.

The rules

  • The code has four gems from six colours (five from eight on Hard).
  • On Easy all gems in the code are different; on Classic and Hard a colour may repeat.
  • Each gold light is one gem of the right colour in the right place.
  • Each silver light is one more gem of a right colour, but in a different place.
  • You win by matching the code exactly within your tries: ten, or twelve on Hard.

Cracking a code step by step

1. Open with pairs

On Classic, a first guess such as red, red, blue, blue tests two colours at once and also hints at their places. If no light comes on, both colours are out and the puzzle has shrunk a lot.

2. Count the colours first

Add up gold and silver after each guess: that is how many of your colours are in the code. A second guess with two new colours tells you about those. After two or three guesses you usually know which colours are in the code, even if not where.

3. Then find the places

Once you know the colours, move them around. A gem that turns a silver light into a gold one has found its place; a gold light that turns silver tells you a gem has left its place.

4. Only guess what could be right

Before you check, test your guess against every earlier row: would each of them have shown the same lights if this were the code? If not, the guess cannot win, and a better one is waiting.

Tips for fewer guesses

  1. Watch the counter. If Codes left barely moves, your guess repeated what you already knew.
  2. Use a known-wrong colour. Once a colour is ruled out, it makes a perfect filler for testing places.
  3. Change one thing at a time when you are close, so each light change has one clear cause.
  4. Remember repeats. On Classic and Hard, a code like red, red, green, blue is allowed.
  5. Save the hint. One opened gem is worth most near the end, when two codes are left.

A short history

Guessing a hidden code from scored clues is an old pencil and paper game, often played with four-digit numbers between two friends. A board version with coloured pegs and small scoring pins became a best-seller in the 1970s, and it was soon one of the first puzzles that early home computers could play against people. Mathematicians later showed that a four-peg, six-colour code can always be found in at most five guesses.

Code Breaker FAQ

Does the order of the lights mean anything?

No. The lights are only counts; they do not line up with the gems of your guess.

Can a colour be counted twice?

Only as often as it appears in the code. Guess red three times when the code has one red, and only one light comes on for red.

What is the best number of guesses?

On Classic, four or five is very good; three is a lucky day. Few enough guesses earns three stars.

Ready for a game? AllFun Code Breaker is free and opens right here in your browser.

Play Code Breaker