Game Guides

Code Breaker (Mastermind): Rules, History, and How to Play

Code Breaker — Pop Play game card showing the colored peg board

What is Code Breaker?

Code Breaker is a two-player code-cracking game with an asymmetric structure:

  • One side picks a secret code — typically four pegs in some combination of six colours, with repeats allowed.
  • The other side has a fixed number of guesses (usually 8 or 10) to figure out the code.
  • After each guess, the code-maker gives feedback: how many of your guessed pegs are the right colour in the right position, and how many are the right colour but in the wrong position.

The cracker wins if they guess the code exactly within the allowed turns; the code-maker wins if all turns elapse without a correct guess.

The game has many regional names — Mastermind, Bulls and Cows, Number Mind, AB Game. Pop Play uses Code Breaker as the in-app name. The mechanics are identical across naming.

How to play

Setup

The code-maker picks a secret code: a sequence of four pegs (positions 1, 2, 3, 4), each peg one of six colours. Repeats are allowed — for example, “Red, Red, Blue, Yellow” is a valid code.

Pop Play handles the code-making automatically when you play against a bot. In two-player mode you set the code at the start of your half-game.

A guess

The cracker submits a 4-peg guess. The code-maker reveals feedback:

  • Black peg for each guessed peg that matches colour AND position of a peg in the secret code.
  • White peg for each guessed peg that matches a colour in the secret code but is in the wrong position.
  • No peg for each guessed peg whose colour doesn’t appear in the secret code at all.

Crucially, each peg in the secret code can match at most one peg in the guess. If the secret has one Red and your guess has two Reds, you’ll get either one black peg (if one of yours is in the right position) or one white peg (if neither is) — never two pegs of feedback for the single Red.

The order of feedback pegs doesn’t tell you which of your guess pegs matched; it just tells you the totals.

Winning

If you place a guess that gets four black pegs (all four colours and positions match exactly), you’ve cracked the code and won.

If you exhaust the allowed turns (typically 8 or 10) without four-black-peg feedback, the code-maker wins.

In Pop Play the standard ruleset is 8 guesses, 6 colours, 4 positions, repeats allowed — the original Mastermind configuration.

A worked example

Secret code: Red, Blue, Red, Yellow

Guess 1: Red, Yellow, Blue, Green

  • Position 1 (Red) matches secret position 1 (Red) → 1 black peg.
  • Position 2 (Yellow) — the secret has Yellow at position 4, so colour matches in wrong position → 1 white peg.
  • Position 3 (Blue) — secret has Blue at position 2 → 1 white peg.
  • Position 4 (Green) — secret has no Green → no peg.

Feedback: 1 black, 2 white, 1 nothing.

Guess 2: Red, Blue, Yellow, Yellow

  • Position 1 (Red) matches secret position 1 → 1 black.
  • Position 2 (Blue) matches secret position 2 → 1 black.
  • Position 3 (Yellow) — secret has Yellow at position 4 → 1 white.
  • Position 4 (Yellow) — wait, but the secret only has ONE Yellow (at position 4), and we already used it for the white peg above. So no extra credit.

Feedback: 2 black, 1 white, 1 nothing.

The cracker now knows: positions 1 and 2 are correct (Red, Blue), position 3 has Yellow somewhere but position 3 itself isn’t Yellow, position 4 isn’t Yellow. From the previous guess they know position 2 also has Blue (consistent). So position 3 is some non-Yellow colour, position 4 is Yellow.

Guess 3: Red, Blue, Red, Yellow → 4 black pegs. Cracked.

This kind of incremental deduction is the entire game.

What makes Code Breaker great

The clean answer: information per turn. Every guess is a query, and every piece of feedback narrows the space of possible codes. The challenge is figuring out which guesses are most informative when you don’t yet know enough to guess the code exactly.

Strong play has a real algorithmic flavour. Donald Knuth published a “five-guess algorithm” in the late 1970s that solves any standard 6-colour, 4-peg Mastermind code in at most five guesses. Subsequent algorithms have reduced the worst-case for related variants. Human players don’t reach Knuth-level consistency, but learning even a fraction of the technique transforms how you approach guesses.

Code Breaker’s history

Mastermind was designed by Mordecai Meirowitz — an Israeli postmaster and telecommunications expert — around 1970. He pitched the game to several major publishers, none of whom were initially interested.

A small UK company, Invicta Plastics, eventually picked it up in the early 1970s and licensed Mastermind worldwide. The game became one of the best-selling deduction games of all time, with lifetime global sales running well into the tens of millions of units.

The game has older intellectual roots: a similar pencil-and-paper game called Bulls and Cows has been played for at least a century in various countries, using digits instead of colours. Meirowitz’s contribution was the colour-peg version with a board that automated feedback.

In 2011, the Mastermind brand and rights were acquired by Hasbro.

The game has been studied extensively in computer science as a benchmark for search algorithms, satisfiability, and information theory. The concept extends naturally to higher-dimensional codes (5 or 6 positions, more colours), though as variant size grows the worst-case turns required grows roughly logarithmically.

Code Breaker strategy primer

For consistent wins:

1. Maximise information per guess

Don’t repeat colours from earlier guesses unless you have a specific reason. Every distinct colour you try gives you direct evidence whether that colour is in the code.

2. Use a structured opening

Most strong players follow a standard 1-2 turn opening:

  • Guess 1: 4 different colours (e.g., Red, Blue, Green, Yellow). Counts how many of those colours are in the code.
  • Guess 2: The other 2 colours plus 2 of the previous 4 (e.g., Black, White, Red, Blue). Combined with guess 1, you now know how many of all 6 colours are in the code.

After 2 guesses you almost always know the colour composition of the code, you just don’t know the positions.

3. Use elimination on positions

Once you know the colour composition, run “is this peg in this position” tests with single-position guesses. A guess with just one new peg differs from your previous best in exactly one position — the feedback delta tells you precisely where that colour belongs.

4. Don’t waste guesses on impossible codes

After each feedback, mentally (or on paper) prune the space of possible codes. A “consistent guess” — one that’s actually possible given all feedback so far — is much better than a guess you’ve already proven impossible.

5. Worst-case planning

Strong players consider not just “what will I learn from this guess if it’s wrong?” but “what’s the WORST-case number of additional guesses I’ll need depending on the feedback?” Knuth’s 1977 algorithm formalises this: pick the guess that minimises the worst-case remaining possibilities.

Code Breaker on Pop Play

Pop Play uses the standard 6-colour, 4-position, 8-guess ruleset. Specifically:

  • Smart bot opponents that use efficient deduction algorithms — the hard difficulty cracks codes consistently in 4-5 guesses.
  • Online multiplayer with friends — both players take turns being code-maker and cracker.
  • Themed worlds — Egyptian Tomb, Crystal Cavern, Alien Planet, and Neon Cyberpunk skins suit the secrets-and-deduction feel.
  • Auto-graded feedback — the app computes feedback pegs for you, no peg-counting errors.

Frequently asked questions

What’s the difference between Code Breaker and Mastermind?

Same game. “Mastermind” is the trademarked commercial name (currently owned by Hasbro). “Code Breaker” is a generic / non-trademarked name used in many digital implementations including Pop Play.

How many guesses do I get?

Standard rule is 8. Pop Play uses 8. Some variants use 10 or 12.

Can the secret code have repeated colours?

Yes — and almost always does, since with 6 colours and 4 positions a non-repeat code is rare. Repeats are allowed in the standard ruleset.

What’s the maximum number of guesses needed with perfect play?

Five. Knuth proved in 1977 that a 6-colour, 4-position code can always be cracked in at most 5 guesses with optimal play. Most casual players take 6-8.

Is there a “best” first guess?

Multiple credible options. A common strong first guess is two pairs of two colours (e.g., Red, Red, Blue, Blue) — Knuth’s algorithm uses this. Four-different-colour guesses (Red, Blue, Green, Yellow) also work well in practice.

Where can I play Code Breaker / Mastermind on mobile?

Pop Play has it free as Code Breaker. Several official Mastermind apps exist as paid downloads; Pop Play’s version is free with no ads.

Pop Play's themed worlds — Code Breaker edition

Same rules, totally different vibe. Each themed world re-skins the board, pieces, and ambient art — 51 worlds across the app, four shown below.

Play Code Breaker 19 board games · No ads · Free
Get free →