IQ Metrics
IIF Certified Assessment Start IQ Test
IIF Certified Assessment
Code Breaker game icon

Brain Games · Logic

Code Breaker

4 pegs from 6 colours, no repeats: 360 possible codes. 10 guesses.

No signup · 3 to 8 minutes · Keys 1 to 6 and Enter work too

In short

What is the Code Breaker game?

Code Breaker is a game of deduction. The computer hides a code of 4 colours, and you guess it. After each guess, clues tell you how many pegs are the right colour in the right place, and how many are right but misplaced. It plays like the classic Mastermind board game, online.

Below: three modes, how many codes there are, how to crack one in fewer guesses, and how deduction relates to IQ.

1,296Possible codes with 4 pegs and 6 colours
5 guessesEnough to crack every one of them with the right strategyKnuth, 1976
4.34The best possible average number of guessesKoyama & Lai, 1993
3 modesClassic, Daily code and Numbers, no signup

How to play

Three ways to play Code Breaker

Pick a mode at the top and press Start. Tap a colour to fill the next hole, then Check. The clues say how many pegs are right, never which ones.

Classic

Deduction: testing ideas against every clue.

  1. A hidden code of coloured pegs. Fill a row and press Check.
  2. ● is a right colour in the right place; ○ a right colour in the wrong place.
  3. Use every clue to crack the code within 10 guesses.
Play Classic

Daily code

Deduction, with a new code every day.

  1. One code a day, the same for everyone.
  2. Your first game of the day is the one that counts for your streak.
  3. The last 30 days stay playable, just for fun.
Play Daily code

Numbers

The same deduction, with digits.

  1. The code is made of digits, as in the old game Bulls and Cows.
  2. ● is a right digit in the right place; ○ a right digit in the wrong place.
  3. Nothing depends on colour, and screen readers read every row.
Play Numbers

The maths

How many codes there are

Colours to the power of pegs: 6 × 6 × 6 × 6 = 1,296. Without repeats, 6 × 5 × 4 × 3 = 360.

LevelPossible codes
Easy: 4 pegs, 6 colours, no repeats360
Classic: 4 pegs, 6 colours1,296
Hard: 5 pegs, 8 colours32,768

The bars use a log scale, because every extra peg multiplies the number of codes.

Strategy

How to crack a code in fewer guesses

Good players do four things:

  1. Open with two pairs, such as 1-1-2-2: it is the first guess of Knuth’s strategy.
  2. Find the colours first, then their places.
  3. Make every guess fit all the clues so far; the Show codes left switch tells you how many codes still fit.
  4. Hold a colour to note it “not in the code”, so you never use it by mistake.

How the clues work

Three examples, with repeated colours

A dot (●) is a right colour in the right place; a ring (○) is a right colour in the wrong place. Each peg of the code counts only once. Colours are written as numbers here.

Guesses against the code 1-1-2-3

  1. Guess 1-2-3-4 gives ● ○ ○: the first 1 is in the right place, the 2 and the 3 are in the code but elsewhere, and there is no 4.
  2. Guess 1-1-1-1 gives ● ●: the code has exactly two 1s and both are in place, so the other two 1s earn nothing.
  3. Guess 3-3-1-1 gives ○ ○ ○: only one of the two 3s counts, because the code has one 3; both 1s count, but neither is in place.

The rule

  1. Count the dots first: the same colour in the same hole.
  2. Then, for each colour, take the smaller of its count in your guess and in the code, and add these up.
  3. Take away the dots: what is left are the rings.

So each peg earns a dot or a ring, never both, and the clues never say which pegs they mean.

Mastermind

How do you play the Mastermind board game?

Here is how to play Mastermind: one player hides a row of 4 coloured pegs, and the other tries to find it in a set number of guesses. A black peg means right colour, right place; a white peg, right colour, wrong place.

Where it came from

Mordecai Meirowitz, an Israeli postmaster, invented Mastermind in 1970, and Invicta Plastics in England launched it in 1971 and 1972. Mastermind is a trademark of its owner; Code Breaker is our own game.

Play a Mastermind-style game online

Code Breaker plays the same game against the computer: 4 pegs and 6 colours on the classic board, with a shape on every colour so anyone can play.

A Mastermind solver

Code Breaker doubles as a Mastermind solver: after each game it shows how Donald Knuth’s strategy would have cracked your code. In 1976 he showed it never needs more than 5 guesses.

How to play Mastermind, step by step

  1. The code maker hides 4 pegs chosen from 6 colours; colours may repeat.
  2. The code breaker places a guess of 4 pegs.
  3. The code maker answers with black pegs (right colour, right place) and white pegs (right colour, wrong place).
  4. Use every clue so far for the next guess, and crack the code before the guesses run out.

Skills

What the game uses

Deduction

Turning clues into facts: if this row has no dots and no rings, none of its colours is in the code.

Working memory

Keeping every earlier clue in mind while you build the next guess.

Testing ideas

Choosing a guess that tells you the most, whatever the answer turns out to be.

And IQ

Does Code Breaker test your IQ?

Not on its own, but it uses two skills IQ tests measure. Each guess is a small experiment, so the game rewards deduction, part of fluid reasoning. Keeping every clue in mind at once leans on working memory.

Practice makes you better at the game; there is little evidence it raises IQ (Simons and colleagues, 2016). For a wider check of your reasoning, try the logical reasoning test or take the online IQ test.

The five areas of a modern IQ test

  1. Verbal comprehensionWord knowledge and reasoning in words
  2. Visual spatialSeeing and turning shapes in your mind
  3. Fluid reasoningFinding the rule in a new problemClosest to this game
  4. Working memoryHolding information and using itAlso used
  5. Processing speedQuick, accurate simple work

The five primary index areas of the WISC-V (children, 2014) and the WAIS-5 (adults, 2024). See WAIS-5 index scores explained.

FAQ

Code Breaker: questions people ask

How do the clues work with repeated colours?

Each peg in the code can be matched only once. For each colour, the smaller of its count in your guess and in the code counts; dots (right place) are counted first, and rings make up the rest.

Can every code be cracked in 5 guesses?

Yes, with 4 pegs and 6 colours. Donald Knuth showed in 1976 that a careful strategy cracks every one of the 1,296 codes in 5 guesses or fewer. After each game we show how his strategy would have cracked your code.

What is the best first guess?

Two pairs, such as 1-1-2-2 (two pegs of one colour and two of another), is the first guess of Knuth’s strategy. Many players prefer four different colours, to learn which colours are in the code.

What is the best possible average?

About 4.34 guesses, found by Kenji Koyama and Tony Lai in 1993 with a full computer search. That strategy needs 6 guesses for a few codes.

Is it the same as Bulls and Cows?

It is the same idea. Bulls and Cows is an older pencil-and-paper game with digits: a bull is a right digit in the right place, a cow a right digit in the wrong place. Our Numbers mode plays the same way.

Is it like Wordle?

Both give clues about which parts of a guess are right. Wordle’s clues sit on each letter; Code Breaker’s clues only say how many pegs are right, which makes it a purer test of deduction.

Can I play if I am colour-blind?

Yes. Every colour has its own shape, you can show numbers on the pegs, and the Numbers mode uses digits only. The clue markers differ by shape (a dot or a ring), not by colour.

When does the daily code change?

At midnight where you are. Everyone gets the same code for the same date; your first game of a day counts, and the last 30 days stay playable.

Is it good for your brain?

It is good practice in deduction: testing an idea against every clue at once. There is no good evidence that it raises IQ. A full IQ test measures reasoning across many kinds of questions.

Is Code Breaker the same as Mastermind?

It is the same idea: a hidden code of coloured pegs, and clues for right colour, right place and right colour, wrong place. Mastermind is a trademark of its owner; Code Breaker is our own version.

How many guesses do you get in Mastermind?

Most boards have rows for 12 guesses; some sets have 10, 8 or 6. Here each level shows how many guesses you have.

Can I challenge a friend?

Yes. After you crack a code, send the link: your friend gets the same code and sees both scores.

Is it free?

Yes. It is free to play, with no signup, and your scores stay in your browser.

Sources

The research behind this page

  1. Knuth, D. E. (1976). The computer as master mind. Journal of Recreational Mathematics, 9(1), 1–6.
  2. Koyama, K., & Lai, T. W. (1993). An optimal Mastermind strategy. Journal of Recreational Mathematics, 25(4), 251–256.
  3. Simons, D. J., Boot, W. R., Charness, N., Gathercole, S. E., et al. (2016). Do “brain-training” programs work? Psychological Science in the Public Interest, 17(3), 103–186. doi:10.1177/1529100616661983

The full picture

Your logic is one piece. Now see the whole picture.

Each game looks at one skill. The IQ test brings speed, reasoning and memory together in one score, with your percentile and a certificate.

Find Your IQ Score

Instant results · 10–20 minutes