Skip to content

How to play Codebreaker: the colour code game, rules and strategy

One player hides a code of four colours. The other guesses, and each guess earns clues: right colour in the right place, or right colour in the wrong place. Here are the rules, the older number version and how to crack codes fast.

By our team. Published . 2 sources.

Play it free in Parlour

Codebreaker is Parlour's name for the classic code-breaking game for two players. One player, the code setter, secretly chooses a code: four pegs in a row, each one of six colours. The other player, the codebreaker, tries to find the exact code, colours and order, in a limited number of guesses. After every guess the setter gives clues: how many pegs are the right colour in the right place, and how many are the right colour in the wrong place [2].

The colour version was invented in 1970 and is based on a much older pencil-and-paper game played with numbers, called bulls and cows [1] [2]. Both reward the same thing: squeezing as much information as possible out of every guess.

What you need

  • A board or sheet with a row for each guess: usually 10 or 12 rows, though versions with 8 or 6 exist [2].
  • Code pegs in six colours.
  • Small key pegs, or pencil marks, for the clues.

The rules

  1. Set the code. The setter picks four colours in order and hides them. Agree first whether a colour may appear more than once (repeats) and whether blanks are allowed [2]. With six colours and repeats allowed there are 1,296 possible codes [2]; without repeats there are 360.
  2. Guess. The codebreaker places four colours in the first row.
  3. Give clues. For each peg that is the right colour in the right place, the setter gives one coloured key peg. For each peg that is the right colour in the wrong place, one white key peg [2]. The clues do not say which pegs they refer to.
  4. Repeat on the next row, using the clues so far.
  5. Win by guessing the exact code within the allowed rows. If the rows run out, the setter wins. In a match, players swap roles and count how many guesses each needed.

Scoring clues with repeated colours

Each peg in the code can be matched only once. Count right-place matches first. Then, among the pegs left over on both sides, count colours that match in the wrong place, each code peg used at most once. For example, if the code is red, blue, blue, green and the guess is blue, blue, blue, blue, the clue is two right-place (the two middle pegs) and nothing else, because the code has only two blues.

Bulls and cows, the number version

Bulls and cows is played with four-digit numbers, usually with all digits different. A correct digit in the correct position is a bull; a correct digit in the wrong position is a cow. If the secret is 4271 and the guess is 1234, the answer is one bull and two cows [1]. Each player usually sets a number for the other, and the first to find the other's number wins [1]. It was among the first games written for computers: a version ran at Cambridge before 1970 [1].

How to crack a code

Open with two pairs

A strong first guess is two pairs, such as red, red, blue, blue. In 1976 Donald Knuth showed that a method starting with exactly that kind of guess can always find the code in five guesses or fewer [2].

Only guess codes that could be right

After a few rows, check each guess against every clue so far. If your guess would not have produced the same clues as the real code did, it cannot be the answer. A simple rule that works well: always play a code that is consistent with every clue you have.

Change a little at a time

When a guess scores well, keep most of it and change one or two pegs. The change in the clues tells you which pegs mattered.

Use colours you have ruled out

Once you know a colour is not in the code, it is a perfect filler. Putting it in a position tells you that position's clue came from the other pegs.

Write down what you know

Keep a note of each colour: in the code, not in the code, or unknown, and which positions it cannot be in. Most mistakes come from forgetting an earlier clue.

Clue on a guessWhat it tells you
Four right placeSolved
Nothing at allNone of those colours is in the code
Four in total, any mixYou have all four colours; now find the order
Right place onlySome pegs are fixed; try moving the others

How good can you get?

The best known method needs about 4.34 guesses on average, and never more than six [2]. Knuth's method trades a little average for the guarantee of five. In everyday play, solving most codes in five or six guesses is very good, and with ten rows you have plenty of room to learn.

Making it harder or easier

  • No repeats makes the game easier: fewer codes, and every colour clue counts once.
  • Fewer rows makes it harder. With six rows you need to plan from the first guess.
  • Swap roles. Setting codes is a game too. Codes with repeated colours are often the hardest to find.

Common questions

How many possible codes are there with four pegs and six colours?
1,296 if colours may repeat, and 360 if every colour must be different [2].
Can you always solve the code in five guesses?
Yes, with the right method. Knuth showed in 1976 that a strategy starting with two pairs finds any four-peg, six-colour code in five guesses or fewer [2].
What is the best first guess?
Two pairs, such as red, red, blue, blue. It is the opening of Knuth's five-guess method [2].
What is the difference between bulls and cows and the colour game?
Bulls and cows is the older pencil-and-paper version with numbers, usually with no repeated digits. The colour game was invented in 1970 from it [1] [2].
Do the clue pegs show which pegs are right?
No. The clues only count right-place and wrong-place colours, without saying which pegs they mean [2]. Working that out is the game.

Sources

Checked on 11 November 2026.

  1. 1.Wikipedia, "Bulls and cows" (rules, bulls and cows, early computer version): https://en.wikipedia.org/wiki/Bulls_and_cows
  2. 2.Wikipedia, the 1970 colour-peg code-breaking game (rules, number of codes, Knuth's five-guess method, averages): https://en.wikipedia.org/wiki/Mastermind_(board_game)
More game rules