Home › Fun & Games › Mastermind Game

Mastermind Game

The computer hides a secret code of colored pegs. You have 10 guesses to crack it: after each guess, a black peg means right color in the right spot and a white peg means right color in the wrong spot.

Last updated:

    Guess 1 of 10: pick colors.

    Advertisement
    Advertisement

    How to use the Mastermind Game

    1. Choose a mode: Classic (4 pegs, 6 colors) or Hard (5 pegs, 8 colors), and whether the secret may repeat colors.
    2. Build a guess by clicking colors in the palette, dragging them into the holes, or typing their numbers. Click a hole to select it; click it again to clear it.
    3. Press Check (or Enter). Each black peg means one peg is the right color in the right position; each white peg means a right color in the wrong position.
    4. Use the clues to narrow it down. Turn on the counter to see how many codes still fit, or press Hint for a guess that matches every clue so far.
    5. Crack the code within 10 guesses to win. The secret is revealed at the end either way.

    How the feedback is scored

    Feedback is worked out in two steps. First, count the pegs that match exactly in color and position: each one gives a black peg. Then, for the remaining pegs, count for every color how many times it appears in both your guess and the secret code and take the smaller number: those give white pegs. A secret peg is never counted twice.

    SecretGuessFeedbackWhy
    Red Blue Green YellowRed Green Orange Orange1 black, 1 whiteRed is in the right spot; green is in the code but in the wrong spot.
    Red Red Blue BlueRed Blue Red Orange1 black, 2 whiteFirst red is exact; the second red and the blue are in the code but misplaced.
    Green Green Green BlueGreen Yellow Yellow Yellow1 black, 0 whiteOnly one green in the guess, and it is already counted as black.
    Purple Orange Yellow RedRed Purple Orange Yellow0 black, 4 whiteAll four colors are right, but none is in its place.

    Mastermind strategy tips

    • Open with two pairs. A guess like Red Red Orange Orange tells you about two colors at once and is the opening of Donald Knuth's strategy, which never needs more than five guesses in the classic game.
    • Only play codes that could still be right. Before each guess, check it against every earlier clue. If it would have produced different feedback for any earlier row, it can't be the secret. The "codes still possible" counter and the Hint button do this check for you.
    • Watch the totals. Black plus white tells you how many of your colors are in the code. If a guess gets zero pegs, every color in it is out.
    • Change one thing at a time when you are close. Swapping two pegs or replacing one color makes it much easier to see what the feedback is telling you.
    • Remember duplicates. When duplicates are on, a code like Blue Blue Blue Green is possible, so don't rule out repeated colors too early.

    Number of possible codes

    ModeDuplicates allowedNo duplicates
    Classic: 4 pegs, 6 colors64 = 1,2966 × 5 × 4 × 3 = 360
    Hard: 5 pegs, 8 colors85 = 32,7688 × 7 × 6 × 5 × 4 = 6,720

    Keyboard: type 1–6 (or 1–8) to place colors, Backspace to remove one, ← → to move between holes and Enter to check. Double-click an earlier guess to copy it into the current row.

    Frequently asked questions

    How do the black and white pegs work?

    After each guess you get one black peg for every peg that has the right color in the right position, and one white peg for every other peg whose color is in the code but in a different position. Each peg in the secret is counted only once, so the total of black and white pegs is never more than the number of pegs.

    Does the order of the feedback pegs matter?

    No. The feedback pegs are always shown with the black ones first, so they don't tell you which positions are correct. Working that out is the puzzle.

    How many possible codes are there?

    With 4 pegs and 6 colors and duplicates allowed there are 6^4 = 1,296 possible codes. Without duplicates there are 6 × 5 × 4 × 3 = 360. Hard mode with 5 pegs and 8 colors has 8^5 = 32,768 codes with duplicates, or 6,720 without.

    Can every code be solved in 10 guesses?

    Yes, easily. In 1977 Donald Knuth showed that any classic 4-peg, 6-color code can be found in at most five guesses with the right strategy. Ten guesses leaves plenty of room for normal play.

    What is a good first guess?

    For the classic game, a guess with two pairs of colors such as red, red, orange, orange is a strong start; it is the first guess in Knuth's five-guess strategy. After that, try to make guesses that are consistent with all the feedback you have received.

    Is this the same as Bulls and Cows?

    It is very similar. Bulls and Cows is an older pencil-and-paper game played with digits, where bulls are like black pegs and cows are like white pegs. Mastermind uses colored pegs instead of numbers.

    What does the hint do?

    The hint fills in your current row with a code that is consistent with every clue you have received so far, chosen at random from the codes that are still possible. Using it doesn't end the game, but it is noted in your result.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Word Guess GameGuess the hidden five-letter word in six tries. Unlimited games, stats and hard mode.Sudoku OnlinePlay free Sudoku with 4 difficulty levels, notes, hints and a timer.Tower of HanoiPlay the Tower of Hanoi puzzle with 3 to 8 disks, or watch it solve itself in the fewest moves.Memory Card GameFlip cards and match emoji pairs on 4×3 to 6×6 grids, with moves, timer and best scores.SolitairePlay classic Klondike Solitaire with Draw 1 or Draw 3 and undo.Spider SolitairePlay Spider Solitaire online with 1, 2 or 4 suits, hints, unlimited undo and a timer.Play Chess vs ComputerPlay chess online against the computer at 8 difficulty levels.Connect FourPlay Connect 4 online against the computer or a friend.Snake GamePlay classic Snake online with speeds, wall modes and high scores.Tic Tac ToePlay tic tac toe against an unbeatable AI or a friend.Block Puzzle GameClassic falling blocks puzzle game with levels and high score.MinesweeperPlay classic Minesweeper: 3 difficulties, flags, timer and a safe first click.2048 GamePlay 2048 online with swipe controls, undo and best score.HangmanClassic friendly hangman word game with categories, hints and difficulty levels.Flappy GameTap to flap a round chick through bamboo gaps and beat your high score.Dino Runner GameJump cacti and duck buzzing beetles in an original endless desert runner.Typing GameType the falling words before they land; level up and track your WPM and accuracy.Math Quiz GameTimed mental math rounds with four operations, five levels, streaks and high scores.Flag QuizGuess the flags of all 196 countries in four modes, from multiple choice to timed.Map QuizFind countries on a clickable world map or name the highlighted one, by continent.Periodic Table QuizLearn all 118 elements: quiz symbols, names and atomic numbers or click them on the table.Spelling Bee GameMake words from 7 honeycomb letters, always using the center letter. New daily puzzle.Jigsaw PuzzleTurn a sample picture or your own photo into a 12 to 150 piece jigsaw puzzle and solve it.Sliding PuzzlePlay the 15 puzzle and 3×3 to 6×6 sliding tile puzzles with numbers or your own photo.Mahjong SolitaireMatch pairs of free tiles to clear the Turtle and two smaller layouts, with hints, shuffle and undo.Scrabble Word FinderFind the highest-scoring words from your rack, with blank tiles, patterns and bingo bonus.Wordle SolverEnter your guesses and colours to see every possible answer and the best next guess.Crossword SolverFind words that fit a crossword pattern like c?t from the length and the letters you know.Word Search GeneratorMake a word search puzzle from your words, play it online or print it with an answer key.Pong GamePlay classic Pong online against the computer on 3 levels or with a friend, first to 11.Breakout GameClassic brick breaker game with levels, power-ups and lives. Play with mouse, touch or keyboard.Whack-a-MoleWhack the moles before they hide in 30 or 60 second rounds. Speed increases, best score saved.Simon Says GameRepeat the growing color and sound sequence. Classic memory game with strict mode and high score.CheckersPlay checkers online against the computer or a friend, with kings, undo and hints.ReversiPlay Reversi (Othello rules) online vs a 3-level computer or a friend, with move hints.GomokuGet five in a row on a 15×15 board against a smart computer or a friend.Battleship GamePlace your fleet and sink the computer's ships in this classic naval guessing game.FreeCellPlay FreeCell solitaire online with the classic numbered deals, undo, hints and auto-move.Kakuro PuzzlePlay generated cross-sum kakuro puzzles in several sizes with pencil marks and a combination helper.Killer SudokuPlay generated killer sudoku puzzles with cage sums, pencil marks, a cage combo helper and hints.Ludo GamePlay Ludo online with 2-4 players or against the computer: roll, capture and race home.Match 3 GameSwap gems to match 3 or more, trigger cascades and special gems, and beat each level's target.Snakes and LaddersPlay the classic board game online with 2-4 players or against the computer.Space Shooter GameRetro arcade space shooter: blast alien waves and meteors, grab power-ups and beat your high score.Spades Card GamePlay Spades online with a computer partner: bid tricks or nil, trump with spades, avoid bags.Stack Tower GameTap to drop sliding blocks and build the tallest tower. Perfect drops earn bonus points.US States QuizFind the 50 states on a clickable US map, type them all from memory, or match state capitals.Virtual Bubble WrapPop endless bubble wrap with click, touch or drag. Satisfying pop sounds and a pop-it fidget mode.Word Grid GameFind words in a 4x4 or 5x5 letter grid by dragging across adjacent letters before time runs out.Word Ladder GameChange one letter at a time to turn one word into another. Daily and random word ladders.Chess PuzzlesSolve chess puzzles online: mate in 1, 2 and 3 plus tactics, with hints, a rating and streaks.Clicker GameIdle clicker: mine gems, hire builders, buy upgrades, rebirth for stars and earn while you're away.Color by NumberTap numbered pixels to color pictures, or turn your own photo into a color by number puzzle.Online Coloring PagesColor animal, holiday and mandala pages online with bucket fill and brushes, then print or save PNG.Connections Word PuzzleGroup 16 words into 4 hidden categories. New daily puzzle, full archive, shareable results.Daily Crossword PuzzleA free new crossword every day: quick 5x5 mini or a bigger 13x13, with check, reveal and timer.Farkle Dice GamePlay Farkle online vs the computer or pass-and-play: pick scoring dice, risk it or bank to 10,000.Gin RummyPlay Gin Rummy vs the computer: draw, discard, knock or go gin. Melds found automatically.Jeopardy-Style Quiz Board MakerMake a categories-and-points quiz board, then play it full screen with teams and live scores.Name All Countries QuizType as many of the world's 197 countries as you can in 15 minutes while the map fills in.Piano Tiles GameTap the black tiles to play classic melodies. It speeds up as you go; beat your high score.Pinball GamePlay pinball online with real flipper physics, bumpers, a wire ramp, drop targets and multiball.8 Ball Pool GamePlay 8 ball pool online vs the computer or a friend: aim line, power meter, spin and real physics.Cube SimulatorTurn a 3D 2x2 to 5x5 puzzle cube online: drag or type moves, scramble, time solves and undo.TriPeaks SolitairePlay TriPeaks Solitaire free: clear three peaks with up-or-down runs, streak bonuses, undo and hints.Water Sort PuzzlePour colored water between tubes until every tube holds a single color. Endless solvable levels.20 Questions GameThink of an animal or object and the game guesses it with yes/no questions, then learns.24 GameCombine four numbers with + − × ÷ to make 24. Endless solvable hands, timer and a solver.
    See all 141 Online Games →