Play Code Cracking Puzzle Online
Crack the secret colour code using logic and deduction. Each guess gives you feedback: black pegs for correct colour in the correct position, and white pegs for correct colour in the wrong position. A classic Mastermind-style challenge.
Pick colours and submit your guess
What Is Code Cracking?
Code Cracking is a logic-based code-breaking puzzle inspired by the classic board game Mastermind. The computer generates a secret sequence of coloured pegs, and your mission is to deduce that hidden code in as few guesses as possible.
After each guess you receive two types of feedback:
- ⚫ Black peg — a colour that is correct and in the correct position.
- ⚪ White peg — a colour that exists in the code but is in the wrong position.
When all pegs turn black, you've cracked the code. The game is a pure test of logical deduction and strategic thinking — every guess provides information you can use to narrow down the remaining possibilities.
How to Play Code Cracking Online
- Choose your settings. Pick a code length (4, 5, or 6 pegs), select a difficulty level that determines how many colours are available (6, 8, or 10), and toggle duplicates on or off for an extra challenge.
- Build your guess. Tap a peg slot, then tap a colour from the palette to fill it. You can also tap a filled peg to change it.
- Submit and read the feedback. Black pegs mean right colour, right position. White pegs mean right colour, wrong position. No peg means that colour isn't in the code (or is already accounted for).
- Deduce and refine. Use the cumulative feedback from all your guesses to eliminate colours, fix positions, and logically zero in on the secret code.
- Crack the code! Solve it in as few guesses as possible and try to beat your personal best.
Code Cracking Strategy Tips
1. Maximise Information Early
Your first few guesses should use as many different colours as possible. With 4 pegs and 6 colours, two guesses can cover all 6 colours. The feedback from these opening moves tells you exactly which colours are in the secret code — dramatically narrowing your search space.
2. Identify Colours Before Positions
It's generally more efficient to first figure out which colours appear in the code, then work out their arrangement. A Mastermind veteran knows that colour identification is the faster path to the solution.
3. Use Elimination Aggressively
If a guess returns zero black and zero white pegs, none of those colours are in the code. That's extremely valuable — it eliminates multiple colours at once. Keep a mental (or visual) tally of which colours are confirmed in, confirmed out, or uncertain.
4. Lock Down Black-Peg Positions
If a guess earns one black peg, try keeping one colour in place while moving the others. If you still get a black peg, that position is locked. Repeat to pin down each slot individually.
5. The Duplicates Factor
When duplicates are enabled, the puzzle space grows substantially. A 4-peg code with 6 colours and duplicates has 1,296 possibilities versus just 360 without duplicates. Adjust your opening strategy: test for the presence of each colour first, including the possibility that one colour may appear more than once.
6. Think Like Knuth
In 1977, computer scientist Donald Knuth published an algorithm proving that any standard Mastermind code (4 pegs, 6 colours) can be cracked in at most 5 guesses. The optimal approach is to choose the guess that minimises the worst-case number of remaining possibilities — a minimax strategy.
Code Cracking vs Mastermind vs Bulls & Cows
Code Cracking belongs to the same family of code-breaking logic puzzles as Mastermind and Bulls & Cows. The core mechanic is identical — guess a hidden code and receive feedback on correctness — but the details differ:
- Code elements: Mastermind and Code Cracking use coloured pegs, while Bulls & Cows uses digits (0–9).
- Duplicates: Classic Mastermind allows duplicate colours. Classic Bulls & Cows does not allow repeated digits. Code Cracking lets you toggle duplicates on or off.
- Feedback style: Mastermind and Code Cracking use black/white pegs. Bulls & Cows uses "Bulls" (exact match) and "Cows" (colour match, wrong position) — the same information, different terminology.
- History: Bulls & Cows dates back to the 19th century as a paper-and-pencil game. Mastermind was patented in 1970 by Mordecai Meirowitz and published by Invicta Plastics in 1971. Code Cracking is our free digital take on the genre.
- Flexibility: This online version of Code Cracking offers adjustable code lengths (4–6), multiple colour counts (6, 8, or 10), and an optional duplicates mode — far more configuration than the original Mastermind board game.
History of Mastermind & Code-Breaking Puzzles
The concept of a code-breaking guessing game stretches back to the 19th century, when Bulls & Cows was played as a simple pen-and-paper game between friends. Players would write down secret numbers and take turns guessing, using "bull" and "cow" as shorthand for exact and partial matches.
In 1970, Israeli telecommunications expert Mordecai Meirowitz reimagined the concept using coloured pegs on a plastic board. After being turned down by every major toy company, his creation was published by Invicta Plastics in 1971 under the name Mastermind. It became one of the most successful board games of the decade, selling over 50 million copies worldwide.
The game has deep ties to information theory and computer science. In 1977, Donald Knuth published a paper showing that an optimal algorithm can solve any Mastermind puzzle (4 pegs, 6 colours) in at most 5 guesses. The problem has since been studied extensively — larger board sizes remain computationally challenging, and the general Mastermind problem is NP-complete.
Today, Mastermind-style puzzles thrive as digital games. Online code-cracking puzzles like this one let players customise difficulty with different code lengths, colour counts, and duplicate settings — keeping the core logical challenge while adding modern flexibility.
🎯 Love Code-Breaking Puzzles?
Try our Bulls & Cows online game for a digit-based twist on the Mastermind formula. Or explore our best Mastermind-style games article for even more code-breaking challenges.
Frequently Asked Questions
More Puzzle & Strategy Games
If you enjoy Code Cracking, try these other free games on our site: