About Mastermind
Play Mastermind free online. Crack the secret color code in limited guesses using logic and deduction. Supports two-player code-setting mode. No sign-up needed.
How to use
- Pick colors from the palette to build your 4-peg guess. Click each slot in the current row and select a color — duplicates are allowed, so the secret code might contain the same color more than once. Take your time choosing, as each guess gives you valuable information to work with on subsequent rounds.
- Submit your guess and read the feedback pegs carefully. A black peg means one of your colors is the correct color in the correct position. A white peg means one of your colors appears in the code but is in the wrong position. No peg means that color does not appear in any remaining unmatched position. The feedback pegs are not ordered — they do not tell you which specific slot is correct.
- Use deductive logic to narrow down the secret code with each guess. Start by testing distinct colors to determine which colors are in the code. Once you know the colors, use subsequent guesses to figure out their correct positions. A strong strategy is to change one or two colors at a time between guesses so you can isolate exactly which changes affect the feedback.
- Crack the code before you run out of attempts to win. Most Mastermind games give you 10 to 12 guesses, which is generous if you use systematic deduction. Expert players can typically solve any 4-peg, 6-color code in five guesses or fewer using an optimal strategy similar to the one published by Donald Knuth in 1977.
Frequently asked questions
How do you play Mastermind?
Mastermind is a code-breaking game where one player (or the computer) creates a secret code of 4 colored pegs, and the other player tries to guess it. After each guess, you receive feedback in the form of black and white pegs: a black peg means you have the right color in the right position, and a white peg means a correct color is in the wrong position. The feedback pegs are not ordered, so you do not know which of your pegs earned which feedback — this is what makes the deduction challenging. You must crack the code within a limited number of guesses.
Can two players play?
Yes — in two-player mode, Player 1 sets the secret code and Player 2 tries to crack it. After the round, you can swap roles so the guesser becomes the code-maker. This is how the original board game works and adds a social element to the puzzle. The code-maker can try to choose codes that are especially difficult to guess, such as codes with duplicate colors or unusual patterns that defy common opening strategies.
What is the best strategy for Mastermind?
The most effective strategy is systematic elimination. Start with a guess that uses as many different colors as possible to quickly determine which colors are in the code. On subsequent guesses, change only one or two colors at a time so you can precisely attribute changes in feedback to specific slots. Donald Knuth published a mathematically optimal strategy in 1977 that guarantees cracking any 4-peg, 6-color code in at most five guesses. The key insight is to choose each guess so that it maximally reduces the remaining possibilities, regardless of which feedback you receive.
What do the feedback pegs mean exactly?
A black peg means one of your guessed colors is exactly the right color in exactly the right position. A white peg means one of your guessed colors appears somewhere in the secret code, but you placed it in the wrong position. Crucially, the feedback pegs are presented in no particular order — a black peg on the left does not necessarily correspond to your leftmost guess slot. Also, each peg in the secret code can only match one peg in your guess, so duplicates are handled carefully. If the code has one red and you guess two reds, you will only get one feedback peg for red.
How was Mastermind invented?
Mastermind was invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. He initially struggled to find a manufacturer, but the game was eventually published by Invicta Plastics in the UK in 1971. It became a massive worldwide hit, selling over 50 million copies. The game is based on an older pencil-and-paper game called Bulls and Cows, which uses numbers instead of colors. Mastermind's elegant design — simple rules but deep logical complexity — has made it a staple of game theory and computer science education.
Can the secret code contain duplicate colors?
Yes — the secret code can use the same color more than once, and this is one of the trickiest aspects of the game. A code like Red-Red-Blue-Red is perfectly valid. When duplicates are present, the feedback logic becomes more nuanced: each code peg can only pair with one guess peg. If the code has two reds and you guess three reds, only two feedback pegs will be generated for red. Beginners often overlook duplicates, so always consider the possibility when your feedback does not match your expectations.
Is this game free?
Completely free with no ads, no sign-up, and no downloads. Runs entirely in your browser on any device. If you enjoy logic and deduction games, try
Minesweeper,
Sudoku, or
Number Sequence Puzzle for more brain-teasing challenges.
Part of ToolFluency’s library of free online tools for Games & Fun. No account needed, no data leaves your device.