Guess the secret 4-color code in as few tries as possible. Black pegs = right color & position. White pegs = right color, wrong position.
Crack the Code is a free online logic puzzle based on the classic board game Mastermind, invented in 1970 and still one of the purest tests of systematic deductive logic ever designed. Each guess gives you feedback - how many pegs are the right color in the right position, and how many are the right color but wrong position - and every optimal guess should narrow the remaining possibility space as much as mathematically possible.
This code-breaking game is directly related to hypothesis testing and the scientific method: you form a guess (hypothesis), get feedback (an experiment's result), and use that to eliminate possibilities before your next attempt. Mathematicians have proven that any 4-peg, 6-color Mastermind game can be solved in 5 guesses or fewer with optimal play - most people take 7-8, making this a genuinely challenging free logic puzzle for deduction enthusiasts.
Computer scientist Donald Knuth proved in 1977 that an optimal strategy could always solve a 6-color, 4-peg Mastermind puzzle within 5 guesses, a result now known as "Knuth's algorithm." While most human players won't reach that theoretical minimum, understanding the underlying elimination logic - locking in confirmed colors and positions, then systematically testing remaining possibilities - dramatically improves your code-breaking speed on this free logic game.
Starting with two colors repeated twice each (like AABB) identifies which colors are present before worrying about exact position.
Once a color gives zero feedback pegs, eliminate it entirely from future guesses in this logic puzzle.
Once a peg shows "correct position," keep it fixed and only vary the remaining slots.
Fans of classic board games, puzzle enthusiasts looking for a free deduction challenge, students learning about the scientific method and hypothesis testing, and anyone who enjoys Wordle-style elimination games will find Crack the Code an engaging brain-training exercise with real cognitive science behind it.
This puzzle is built on the logic of Mastermind, a codebreaking board game invented in 1970 by Israeli telecommunications expert Mordecai Meirowitz, which went on to sell over 55 million units worldwide and remains one of the best-selling games ever produced. The elegant part of the original design is the feedback system: after each guess, you are told how many digits are correct and in the right position, and how many are correct but in the wrong position, without being told which specific digits those are. This partial-information feedback loop is what makes the game a genuine deduction exercise rather than simple trial and error.
Mathematically, Mastermind has been studied extensively in computer science, and it has been proven that the classic version of the game can always be solved within five guesses using an optimal strategy, a result first demonstrated by Donald Knuth in a well-known 1977 paper - though achieving that optimal solve rate reliably by hand under time pressure is a very different challenge from doing it with unlimited time and a notepad.
The strongest early-game strategy is to use your first couple of guesses purely to gather information about digit frequency, deliberately choosing guesses with repeated or varied digits to map out which numbers are actually in the code at all, before worrying about their positions. Only once you know which digits are involved does it become efficient to test positional arrangements, since testing position before confirming which digits exist wastes guesses on combinations that may not even be possible.
For a different flavor of pure deduction, Zebra Puzzle uses static logical clues instead of active feedback, and Cognitive Reflection Test measures a related but distinct skill: whether your intuitive first answer to a tricky problem is actually correct.
Mathematically, any 4-peg, 6-color Mastermind puzzle can be solved in 5 guesses or fewer with perfect play, first proven by Donald Knuth in 1977.
Yes - the secret code can include repeated colors, which is part of what makes systematic elimination necessary rather than simple guessing.
Yes, completely free with unlimited puzzles and no signup required to play Crack the Code.
It's a digital version of Mastermind, the classic code-breaking game where you deduce a hidden color sequence using feedback pegs after each guess.
Start with an even spread of colors to gather maximum information, then use the feedback pegs (correct color/position vs. correct color/wrong position) to narrow possibilities systematically.
With optimal play, a standard 4-peg, 6-color Mastermind game can always be solved in 5 guesses or fewer, according to Donald Knuth's classic 1977 analysis.
It trains deductive reasoning and constraint satisfaction β using each clue to logically eliminate incorrect possibilities rather than guessing randomly.