How to Solve Mastermind
Mastermind is a logic puzzle where you try to crack a hidden color code using a series of guesses and feedback. After each guess, the game gives you clues that show how many colors are correct and how many are in the correct positions. With a few simple rules and logical solving techniques, you can solve Mastermind codes without guessing randomly.
This guide explains how to play Mastermind, how to read the feedback pegs, and the best Mastermind solving strategies for beginners. Once you understand how the clues work, even longer and more challenging color codes become much easier to solve.
What Is Mastermind?
Mastermind is a code-breaking logic game in which you try to determine a hidden sequence of colored pegs. The secret code is hidden from you, and your goal is to discover the exact colors and positions within a limited number of guesses.
After every guess, the game provides feedback using colored pegs. A black peg means that a color is correct and in the correct position. A white peg means that a color is correct but is in the wrong position.
If a color receives no peg, it means that the color does not appear in the hidden code, subject to the game's rules about duplicate colors.
The puzzle can be solved through logic and deduction. The goal is not to guess randomly, but to use the feedback from each attempt to eliminate impossible codes.
How Does Mastermind Feedback Work?
Understanding the feedback is the most important part of learning how to solve Mastermind.
Each guess is compared with the hidden code. The feedback tells you how many guessed colors match the secret code and whether they are in the correct positions.
A black peg means the guessed color is correct and is in exactly the right position.
A white peg means the guessed color appears in the hidden code but is in a different position.
A guess that receives no feedback pegs tells you that none of the guessed colors appear in the hidden code.
For example, if your guess receives:
● ● ○ ○
the feedback indicates that two guessed colors are correct and in the correct positions, while the remaining guessed colors do not match the hidden code in the relevant way.
The exact number of black and white pegs is what makes Mastermind a logic puzzle. Every piece of feedback gives you information that can be used to eliminate possible secret codes.
Mastermind Rules
Before solving your first puzzle, remember these basic Mastermind rules:
- The hidden code contains a fixed number of colored pegs.
- Your goal is to discover both the correct colors and their positions.
- A black peg means a correct color in the correct position.
- A white peg means a correct color in the wrong position.
- No feedback for a color means that color is not part of the code, subject to duplicate-color rules.
- Use the feedback from every guess to eliminate impossible codes.
- The game ends when you crack the code or run out of guesses.
The most important rule is to treat every guess as a source of information. Even an unsuccessful guess helps narrow down the possible hidden codes.
How to Solve Mastermind Step by Step
1. Start With a Useful Opening Guess
Your first guess should give you as much useful information as possible. Instead of choosing colors randomly, use an opening combination that helps determine which colors are present in the hidden code.
If the game allows repeated colors, you can also use an opening guess to investigate whether certain colors occur more than once. If repeated colors are not allowed, focus on testing several different colors instead.
The purpose of the first guess is not necessarily to solve the code immediately. It is to gather information that will make your next guesses more precise.
2. Count the Feedback Carefully
After every guess, pay close attention to the number of black and white pegs.
Black pegs are especially valuable because they tell you that both the color and position are correct. White pegs still provide important information because they confirm that a color belongs somewhere in the code, even though its current position is incorrect.
Never ignore a previous result. A clue from an earlier guess can become much more useful after you learn additional information from later guesses.
3. Eliminate Colors That Cannot Be in the Code
If a guess receives no feedback pegs, the tested colors can be eliminated from consideration, according to the game's duplicate-color rules.
This can dramatically reduce the number of possible codes. Keep track of colors that have been ruled out so you do not waste future guesses testing them again.
Eliminating impossible colors is one of the simplest and most powerful Mastermind strategies.
4. Use Black Pegs to Lock In Positions
Once you receive a black peg, you know that one of the guessed colors is already in its correct position.
Keep that position in mind when making future guesses. You can test other positions around the confirmed color while leaving the known match in place.
As more black pegs are discovered, the number of possible arrangements becomes much smaller.
5. Use White Pegs to Move Colors
White pegs tell you that a color belongs in the hidden code but is not in the position where you placed it.
If a color produces a white peg, move it to another position in a later guess. Do not simply remove it from the code because its current position was incorrect.
Combining white-peg information from several guesses can eventually reveal exactly where a color must go.
6. Compare Multiple Guesses
Mastermind becomes much easier when you compare guesses instead of considering each attempt separately.
Suppose one guess produces three matching colors and another produces only one. The difference between those results can tell you which colors are useful and which ones can be eliminated.
Think of the puzzle as a chain of deductions: guess → feedback → elimination → new guess → feedback.
Understanding Black and White Pegs
Black and white pegs provide different types of information, and learning how to combine them is the key to solving difficult Mastermind puzzles.
A black peg confirms both the color and its exact position. Once you have several black pegs, you can concentrate on solving the remaining positions.
A white peg confirms that the color exists somewhere in the hidden code, but its current position is incorrect. You can use this information to systematically move the color through the remaining possible positions.
For example, if a color produces a white peg in one position and later produces a black peg after being moved, you have confirmed its correct location.
The strongest deductions often come from combining several rounds of black and white feedback.
How Multiple Matching Colors Work
Some Mastermind versions allow the same color to appear more than once in the hidden code. When duplicates are allowed, you need to pay close attention to how matching colors are counted.
For example, if your guess contains a color twice but the hidden code contains that color only once, you should not assume that both occurrences will receive matching feedback.
The feedback represents the number of actual matches between your guess and the hidden code. A color can only be matched as many times as it occurs in the secret code.
If your version of Mastermind does not allow duplicate colors, each color can appear only once in the code, which makes this part of the deduction easier.
Common Mastermind Solving Mistakes
Guessing Randomly
One of the biggest mistakes is choosing combinations without considering previous feedback. Every guess should have a purpose, such as testing a new color, checking a position, or confirming a previous deduction.
Ignoring White Pegs
White pegs are valuable clues. They tell you that a color belongs somewhere in the hidden code even though it is currently in the wrong position.
Forgetting Confirmed Positions
Once a black peg confirms a color and position, remember that information. Moving a confirmed color unnecessarily can make the puzzle harder to track.
Testing Too Many New Colors
Introducing too many new colors at once can make it difficult to determine which colors caused the feedback. Once you have identified likely colors, focus on arranging them correctly.
Ignoring Previous Guesses
Every previous guess contains useful information. If you get stuck, review your earlier feedback and look for combinations that are no longer possible.
Tips for Solving Mastermind Faster
- Start with an opening guess designed to gather information.
- Use every black peg to confirm a position.
- Use white pegs to identify colors that need to move.
- Eliminate colors that are proven not to be in the code.
- Compare the feedback from multiple guesses.
- Keep track of confirmed colors and impossible positions.
- When possible, change only a few elements between related guesses.
- Avoid random guessing when previous feedback can narrow the possibilities.
- If duplicates are allowed, carefully track how many times each color can occur.
Mastermind Example
The examples below show how Mastermind guesses receive feedback and how repeated deductions can eventually reveal the hidden color code.


What Happens When You Get Stuck?
Getting stuck is normal, especially when the hidden code has many possible combinations. Instead of guessing randomly, review all of the feedback you have received so far.
Look for colors that have been confirmed, colors that have been eliminated, and positions that a particular color can no longer occupy. Combining these restrictions can reveal new possibilities.
Another useful approach is to make a guess that tests a specific theory. For example, if you know that three colors belong in the code but are unsure of their positions, arrange them differently to determine where they fit.
Try to make every new guess provide useful information, even if it does not solve the code immediately.
How to Get Better at Mastermind
The best way to improve is to play regularly and pay attention to the deductions behind each successful solution. Start with easier codes so you can become comfortable reading black and white peg feedback.
As you improve, focus on solving through deduction rather than intuition. You will begin to recognize useful opening guesses, eliminate impossible colors faster, and use combinations of black and white pegs more efficiently.
With practice, you will also become better at planning guesses that test several possibilities at once.
Play Mastermind Online
Ready to try these techniques? Play a free Mastermind game online and use logic and deduction to crack the hidden color code.
Choose your preferred difficulty to get started:
- Easy Mastermind Puzzles (6 Colors) – Perfect for beginners learning the basics of code-breaking, using logic and deduction to crack the secret combination with a palette of 6 colors.
- Medium Mastermind Puzzles (8 Colors) – Challenge yourself with 8 possible colors and develop more advanced deduction strategies to uncover the hidden code.
- Hard Mastermind Puzzles (10 Colors) – Test your code-breaking skills with 10 possible colors, requiring sharper logic, careful reasoning, and strategic guesses.
Start with Easy to learn the fundamentals, then progress to Medium and Hard as you sharpen your logic, improve your deduction skills, and master the challenge of cracking the secret code.
Frequently Asked Questions About Mastermind
What is Mastermind?
Mastermind is a logic-based code-breaking game where you try to discover a hidden sequence of colored pegs. After each guess, feedback tells you how many colors are correct and how many are in the correct positions.
How do you read Mastermind feedback?
A black peg means that a guessed color is correct and in the correct position. A white peg means that a guessed color is correct but in the wrong position. No matching peg means the relevant color is not part of the hidden code, subject to the game's duplicate-color rules.
Do you have to guess randomly in Mastermind?
No. Mastermind can be solved using logical deductions. Each guess provides feedback that can be used to eliminate impossible codes and determine the correct colors and positions.
What is the best strategy for Mastermind?
Start with a useful opening guess, carefully count the feedback, eliminate impossible colors, and use black and white pegs to determine the correct positions. The best guesses are those that provide useful information rather than simply being random attempts.
What does a black peg mean in Mastermind?
A black peg means that one of the colors in your guess matches a color in the hidden code and is also in the correct position.
What does a white peg mean in Mastermind?
A white peg means that a color in your guess appears in the hidden code but is in the wrong position.
Can colors repeat in Mastermind?
It depends on the version of the game. Some Mastermind versions allow duplicate colors in the hidden code, while others require every color to be different. Always check the rules of the version you are playing.
Can I play Mastermind online?
Yes. You can play Mastermind online and practice the solving techniques explained in this guide.