Mastermind is the classic code-breaking puzzle. Guess the secret 4-color code in 10 attempts, using feedback after each guess to narrow down possibilities.
About Mastermind
Mastermind is a code-breaking game invented in 1970 by Israeli telecommunications expert Mordecai Meirowitz. The computer (or one player) generates a secret code of 4 colored pegs from 6 possible colors. The opposing player has 10 attempts to guess the code. After each guess, the game gives feedback in the form of “key pegs”: one black peg for each color in the right position, one white peg for each color in the right code but wrong position, and no peg for colors not in the code. With perfect logic, any Mastermind code can be cracked in at most 5 guesses regardless of how the codemaker chooses. Mastermind is a fantastic puzzle for teaching deductive reasoning and information theory.
How to Play Mastermind
- Click colors from the palette to build your guess. You need exactly 4 colors per guess. Colors can repeat.
- Press Submit to lock in your guess. The game shows feedback as small key pegs next to your row.
- Black peg: a color is in the right code AND in the right position.
- Yellow peg: a color is in the code but in a different position.
- No peg: that color is not in the secret code at all.
- Use the feedback to refine your next guess. You have 10 attempts. Crack the code to win.
Tips and Strategy
- Your first guess should test 4 different colors. This gives the maximum information — you immediately learn which colors are or are not in the code.
- On guess 2, swap untested colors. Combined with guess 1, you have tested all 6 colors after 2 guesses (if you used 4 distinct colors each).
- Once you know which colors are in the code, focus on permutations. With 4 known colors and 4 positions, there are only 24 arrangements.
- Track your information systematically — note which colors are confirmed in/out of the code and which positions are confirmed/eliminated.
- Avoid repeating colors in early guesses unless you suspect the code has duplicates. Duplicate colors waste information.
- After 4-5 guesses with good information, you should have narrowed down to 2-3 possible codes. Test the most informative remaining guess.
- Donald Knuth proved that 5 guesses always suffices with optimal play. If you take more than 5, your strategy can improve.
History and Origin
Mastermind was invented in 1970 by Mordecai Meirowitz, who took the prototype to several major game companies before Invicta Plastics in England agreed to manufacture it in 1971. It became a global hit, selling over 50 million copies by the 1980s. The iconic box art featuring Bill Woodward as a tuxedoed “codemaker” and his model partner Cecilia Fung defined a generation of puzzle gaming. In 1977, Donald Knuth published an algorithm proving the code can always be cracked in at most 5 guesses with optimal play. Mastermind is widely studied in computer science and game theory.
Variations and Game Modes
Variants include “Super Mastermind” (5-color codes from 8 colors), “Word Mastermind” (letters instead of colors), “Number Mastermind” (number sequences), and computational variants with different feedback rules. The game is mathematically equivalent to a one-sided guessing game in information theory.
Frequently Asked Questions
How do you play Mastermind?
Guess a hidden 4-color code in 10 tries. After each guess, you get feedback: black pegs for correct color in correct position, yellow pegs for correct color in wrong position, nothing for incorrect colors. Use the feedback to deduce the code.
How many colors are there in this Mastermind?
Our version uses 6 colors. With 4 positions and 6 colors (with repetition allowed), there are 6^4 = 1,296 possible codes. The game randomly picks one each game.
How many guesses do I have?
You have 10 attempts to crack the code. With optimal play, any code can be solved in at most 5 guesses, so 10 should be enough even with imperfect strategy.
What is the best opening guess?
Use 4 different colors. Donald Knuth’s algorithm starts with two pairs of colors, e.g. AABB, but for human play, 4 distinct colors gives the most information per guess and is easier to track.
Can Mastermind always be solved in 5 guesses?
Yes. In 1977, Donald Knuth proved that with optimal play, the codemaker can always be defeated in at most 5 guesses, regardless of which code is chosen. With our 10-guess limit, you have plenty of room for non-optimal play.
What does the yellow peg mean?
A yellow peg means one of the colors in your guess is in the secret code but in a different position. The yellow pegs do not say WHICH color or WHICH position — you have to deduce that.
Can the secret code have repeated colors?
Yes. The hidden code is generated by picking 4 random colors (with replacement) from the 6 available. About 51% of codes have at least one repeated color.
How is the feedback ordered?
Pegs show black/correct first, then yellow/present-but-misplaced, with empty slots for the rest. The order of pegs does NOT correspond to the order of your guess — it is just the count of each type.