Code Breaker is a deduction game for two or more players. One player, the code setter, hides a short row of coloured pegs. The other player, the code breaker, tries to guess it. After every guess the setter answers with small key pegs: a black one for each peg that is the right colour in the right place, and a white one for each peg that is the right colour in the wrong place. The breaker wins by finding the exact code before the guesses run out. This guide explains every rule, how to score a guess when colours repeat (the part most arguments are about), the variants people play, and which rules this site uses.

The board on this site: the secret code under the dark shield at the top, ten numbered rows for guesses and a key-peg well beside each row. The first three rows are the worked example further down, each answered with key pegs, blacks first. On the right, the six colours, each with its own shape, and the two kinds of key peg.
Overview
The game has been played with pencil and paper for a long time, often with numbers instead of colours, under the name Bulls and Cows. In the 1970s it became popular as a board game with coloured pegs, a hidden row behind a shield and small black and white scoring pegs. Both versions use the same scoring, and both reward the same skill: reading what a clue rules out, not only what it tells you.
The variant this site uses:
- 4 pegs from 6 colours, repeats allowed, 10 guesses: the classic game, and the default.
- Options: 5 pegs from 8 colours, Repeated colours off, 12 guesses, and 4 digits (Bulls and Cows, four different digits 0 to 9).
- Black and white key pegs, always shown blacks first.
- The code is revealed at the end of every round, win or lose.
Setup
On paper, the setter needs a way to hide the code (a folded card works) and the breaker needs a sheet with ten numbered rows of four boxes, plus a column for the key pegs. Agree on the colours (or letters for them) before you start.
On this site:
- Choose Number of players. With 1 player, the computer sets the code. With 2 to 4 players, one person sets it and the others break it.
- Choose the Code: 4 colours of 6, 5 colours of 8, or 4 digits.
- Decide on Repeated colours (colour codes only). On means a colour may appear more than once in the code.
- Under More options, choose 10 or 12 guesses.
Each colour has its own shape: red circle, blue square, green triangle, yellow diamond, purple star, orange cross, and on the 8-colour board a pink heart and a teal moon. Settings → Colour-safe colours changes the shades for colour-blind players; the shapes stay.
Objective
The breaker’s goal is to name the exact code, every colour in its place, in as few guesses as possible and within the limit. The setter’s goal is a code that survives every guess. In a two-player game, players swap roles each round, so both get to set and both get to break.
Taking turns
A round is short and always runs the same way:
- The setter chooses the code in secret.
- The breaker makes a full guess: one peg in every place.
- The setter scores the guess with key pegs.
- Repeat steps 2 and 3 until the guess is all black or the guesses run out.
With three or four people on this site, the breakers take turns, one guess each, and share the result: if any guess cracks the code, all the breakers win the round.
The rules in detail
Black pegs: right colour, right place
Compare the guess and the code place by place. Every place where the colours match earns one black key peg. Four black pegs (five on the bigger board) means the code is cracked.
White pegs: right colour, wrong place
After the black pegs are counted, set those places aside. For each colour, count how many times it appears in the rest of the code and in the rest of the guess, and take the smaller number. Add these up: that is the number of white key pegs. In short, every peg in the guess earns at most one key peg, and every peg in the code can be matched only once.
Step through scoring a guess
Step 1 of 5: The setter’s secret code is blue, red, red, green. The breaker guesses red, red, blue, blue.
Repeated colours, step by step
Most scoring mistakes happen here, so take the classic example. The code is red, red, blue, blue and the guess is blue, blue, red, red. No place matches, so there are no black pegs. The rest of the code has two reds and two blues; so does the rest of the guess. Two reds plus two blues is four white pegs.
Now the code red, red, blue, green and the guess red, red, red, red. The first two places match: two black pegs. The rest of the code (blue, green) has no red left, so the last two reds earn nothing: no white pegs. The answer is two black, zero white, not two black and two white.
Order of the key pegs
The key pegs never point at a place. On this site the black pegs always come first, then the white ones, then the empty holes. On paper, write them as a count (“2 black, 1 white”) so their position can’t give anything away.
A worked example
The secret code is blue, red, red, green (repeats are on).
- Guess 1: red, red, blue, blue. One black (the red in the second place), two white (one more red and one blue that are in the code but elsewhere). The breaker learns that at least three of the four pegs are red or blue.
- Guess 2: green, green, yellow, yellow. No black, one white. So the fourth peg is green or yellow, and it is not in the first two places if green, nor the last two if yellow. Purple and orange are out.
- Guess 3: red, blue, green, red. No black, four white. Every colour is right, every place is wrong. The code is two reds, one blue and one green. Green is not first or second (guess 2) and not third (guess 3), so it is fourth. Red is not first (guess 3), so blue is first and the reds fill the middle.
- Guess 4: blue, red, red, green. Four black. Cracked in four guesses.
Guess 3 fitted every clue so far, so it might have been the code. It wasn’t, but its answer settled the colours at once, and only one code was left.
Guesses that can’t be made
On this site, a guess must fill every place, and a guess you already tried is refused instead of costing a turn. With 4 digits, a guess uses four different digits, like the code.
No undo
Every guess shows its key pegs at once, so there is no taking it back: that would return a guess whose clue you have already seen. Change pegs freely before you tap Check: tap a hole to choose where the next peg goes, or use Delete.
Keeping the code secret on one device
With 2 to 4 players, a pass screen asks everyone but the setter to look away before the code is chosen. The setter fills the holes, or taps Random, and taps Set the code. A second pass screen hands the device to the breakers. The code never appears on the board until the round ends, and the announcements for screen readers never read it out early either.
Winning, losing and scoring
- All black within the limit: the breakers win the round. The result shows how many guesses it took.
- Out of guesses: the setter wins, and the code is revealed.
- The session score: with 2 to 4 players, each round won adds a point to that player’s score, setters and breakers alike. Rematch hands the code to the next player.
- Against the computer: the result tells you whether you cracked the code and in how many guesses. Fewer is better: try to beat your own best.
The classic board-game scoring gives the setter one point for every guess the breaker needs (and an extra point if the code is never cracked); after an even number of rounds, the higher total wins. It is easy to keep on paper next to this site’s count of rounds.
Variants and house rules
| Variant | Code | Possible codes | Notes |
|---|---|---|---|
| Classic | 4 pegs, 6 colours, repeats | 1,296 | The default here |
| No repeats | 4 pegs, 6 colours | 360 | A gentle start for children |
| Big board | 5 pegs, 8 colours, repeats | 32,768 | Long, careful rounds |
| Big board, no repeats | 5 pegs, 8 colours | 6,720 | |
| Bulls and Cows | 4 different digits 0 to 9 | 5,040 | Bulls and cows instead of pegs |
Other house rules you may meet on paper:
- Blanks as a colour. Some groups allow an empty place in the code, which works like a seventh colour. This site doesn’t.
- Fewer guesses. Eight guesses makes the classic game tense; agree on it before you start.
- Three-digit Bulls and Cows. A quicker version for young players, with three different digits.
Common mistakes and rule disputes
- Counting a peg twice. A code peg that already earned a black can’t also earn a white. Score blacks first, then whites from what is left.
- Giving whites for extra copies. Guessing four reds against a code with one red earns one key peg in total, not four.
- Showing which peg is right. On paper, a setter who lays the key pegs next to the matching places gives away far more than the rules allow.
- Scoring mistakes by the setter. One wrong answer can make a code impossible to find. On paper, the setter should check each answer twice; on this site the game scores every guess.
Glossary
- Code setter (code maker): the player who chooses the secret code.
- Code breaker: the player who guesses it.
- Key pegs: the small black and white pegs that answer a guess.
- Black peg / bull: a right colour (digit) in the right place.
- White peg / cow: a right colour (digit) in the wrong place.
- Consistent guess: a code that agrees with every clue so far, so it could still be the answer.
Play it now
Play Code Breaker against the computer’s secret code, or with 2 to 4 people on one device. When you know the rules, the Code Breaker strategy tutorial shows how to choose your guesses. For another game of hidden information on one screen, try Hangman or Sea Battle.


