Bulls and Cows Number Guessing Game
Guess a secret number with all digits different. Bulls are right digits in the right place, cows are right digits in the wrong place.
Runs in your browser. Your files never leave your device. See how to check
…
How to do it
- 1Choose a mode
You guess or the computer guesses.
- 2Pick the length
3, 4 or 5 digits.
- 3Make a guess
All digits different.
- 4Read bulls and cows
And narrow it down.
- 5Crack the number
Beat your best score.
About this tool
Bulls and cows is a classic code-breaking game for two players that has been played with pencil and paper for over a century. One player thinks of a secret number with all digits different; the other guesses. After each guess the code-maker says how many bulls (right digit, right position) and cows (right digit, wrong position) it scored. With careful logic a 4-digit number can be found in about five to seven guesses. This version lets you play both sides: crack the computer's number, or think of your own and watch the computer deduce it.
How to play
Choose 3, 4 or 5 digits. In guess mode, type a number with no repeated digits and press Guess. The history table shows every guess with its bulls and cows. When you score a bull for every digit you have won. A counter shows how many numbers are still possible given all your clues, and you can reveal that list when you are stuck.
Letting the computer guess
Switch to "Computer guesses my number", think of a number with different digits and keep it secret. The computer offers a guess; you answer with the bulls and cows. It keeps a list of every number consistent with your answers and, each turn, picks the guess that leaves the fewest possibilities in the worst case, the same idea Donald Knuth used for Mastermind. For four digits it usually finishes in five to seven guesses. If you make a mistake in an answer it will tell you that no number fits.
Scoring example
Secret 4271, guess 1234: the 2 is in the right place (one bull), and 1 and 4 are in the number but in the wrong places (two cows). The answer is 1 bull, 2 cows.
Strategy tips
- Start with guesses that share no digits, such as 0123 and 4567, to find which digits are in the number. - Use the total of bulls and cows to count how many of those digits appear. - Then move digits around to find their positions, changing only a little each time. - Keep track of digits you have ruled out completely.
How many numbers are possible?
With four different digits from 0 to 9 there are 10 × 9 × 8 × 7 = 5,040 possible numbers. Three digits give 720 and five digits 30,240. Each clue removes a large share; a good first guess typically leaves only a few hundred possibilities.
Variants
Some people forbid a leading zero or allow repeated digits. Mastermind uses colours instead of digits and allows repeats. The digit-only version here is the most widely played form and works well as a classroom logic exercise.
For teachers
The game practises place value, logical deduction and systematic recording. Ask pupils to explain why a guess is consistent with all earlier clues, or to predict the bulls and cows for a given secret before checking.
Best scores
Your fewest guesses for each length are kept in this browser only and never sent anywhere.
Limits
This is a game for fun and practice; the computer player is strong but not mathematically optimal in every case.
Worked example
Secret 4271, guess 1234 → 1 bull and 2 cows.
Quick facts
- Category: Games & Fun
- Works in your browser, no sign-up, no upload.
- Your input stays on your device.
- Available in English.
- Content last reviewed:
- Official source: Traditional bulls and cows rules (the pencil-and-paper game behind Mastermind); solver chooses the guess that leaves the fewest possibilities in the worst case
Frequently asked questions
What are bulls and cows?
Bulls are right digits in the right place; cows are right digits in the wrong place.
Can digits repeat?
No, all digits in the secret and guesses are different.
How many guesses does it usually take?
About five to seven for four digits with good logic.
Can the computer guess my number?
Yes, switch to computer mode and answer its guesses honestly.
Is a leading zero allowed?
Yes, 0123 is a valid number here.
Is anything stored?
Only your best scores, in this browser.
