Guessed a hidden number five times and still have no idea what it is? That’s how Bulls and Cows feels until you have a Bulls and Cows strategy. Once you use a method, it stops feeling like luck. This post gives you the rules in a minute, a good opening move, one whole game worked out guess by guess, and a practice code to crack yourself.
1. The rules of Bulls and Cows in one minute
One player picks a secret code of 4 different digits, from 0 to 9. The other player guesses it, one 4-digit guess at a time. The first digit of the code can be 0.
After each guess, the code-picker replies with two numbers:
- Bulls are digits that are right and in the right place.
- Cows are digits that are in the code but in the wrong place.
Each digit of the secret counts only once.
Here is an example. Say the secret is 4071 and you guess 1234. The reply is 0 bulls and 2 cows. The 1 and the 4 are both in the code, but in other places. The 2 and the 3 are not in the code at all.
Some versions allow repeated digits, or use a different number of digits. This post uses the version with 4 different digits, and the same method works for the others.
With 4 different digits there are 5,040 possible codes: 10 × 9 × 8 × 7. Each reply rules out many of them.
2. The best opening move
Open with 1234. Any four different digits work just as well, so there is no magic number. Write the reply down.
Why this one? The reply tells you how many digits of the code come from 1, 2, 3 and 4 (the bulls and cows added together). The next guess, 5678, does the same for the digits 5 to 8. Take those two totals away from 4, and what is left is how many of the code’s digits are 0 or 9.
Whatever the reply, the first guess leaves at most 1,440 of the 5,040 codes. In the game below, the reply leaves 1,260.
A reply of 0 bulls and 0 cows is a great one. None of those four digits is in the code, so you can cross out four digits at once.
3. A full game, move by move
The secret code is 4071. The guesser doesn’t know it, but every reply below is exactly what this code gives.
Guess 1: 1234. The reply is 0 bulls and 2 cows. So two of the digits 1, 2, 3 and 4 are in the code, and none of them is in the place you guessed. That means 1 is not first, 2 is not second, 3 is not third and 4 is not fourth. 1,260 codes are still possible.
Guess 2: 5678. The reply is 1 bull and 0 cows. Exactly one of 5, 6, 7 and 8 is in the code, and it is in the place you guessed: the 7 is third. You now know two digits from the first guess and one from this one, so three of the four digits. The last digit is 0 or 9. That leaves 168 codes.
Guess 3: 2071. Now pick a guess that could still be the answer. 2071 fits both replies so far: its 2 and 1 came from the first guess but are not in their old places, its 7 is in third place, and its 0 is a possible 0-or-9 digit. The reply is 3 bulls and 0 cows. Three of its digits are in the code and in their places, and the fourth is not in the code at all. Only four codes still fit: 2073, 2971, 3071 and 4071.
Guess 4: 3071. Pick a guess that tells the four codes apart. Against each of them, 3071 gives a different reply: 2073 gives 2 bulls and 1 cow, 2971 gives 2 bulls and 0 cows, 3071 gives 4 bulls, and 4071 gives 3 bulls and 0 cows. The reply is 3 bulls and 0 cows, so the secret can only be 4071.
Guess 5: 4071. Four bulls: solved. Guesses 3, 4 and 5 each fit every reply before them, so each one could have been the answer. Guesses 1 and 2 were openers, there to find out which digits are in the code.
The take-away: after each reply, cross out what no longer fits, write down the short list, and guess from it.
4. A simple Bulls and Cows strategy for every guess
Use these five steps:
- Step 1: keep notes. Write down each guess and reply, so you don’t have to hold them in your head.
- Step 2: find the digits first. The opening guesses 1234 and 5678 do most of this work. What is left over tells you how many of 0 and 9 are in the code.
- Step 3: then find where they go. Change one part of a guess at a time, and watch how the bulls and cows change.
- Step 4: guess a code that fits every reply. It could be the answer, so you might win on the spot. A guess that can’t be right can still give you information, but it can’t win.
- Step 5: use a filler. Once you know a digit is not in the code (for example, 9), swap one digit of a guess for it and see what changes. If a bull disappears, that digit was in the right place. If a cow disappears, it was in the code but in another place. If nothing changes, that digit isn’t in the code. If guesses can’t repeat digits, use a different absent digit for each filler.
Bulls and Cows tips for faster games
- A total of 4 (bulls plus cows) means you have the right four digits. Only their order is left, and there are at most 24 orders.
- Keep a running list of the places each digit can’t be. This makes the last guesses much easier.
- Check each possible code against every reply so far, not just the last one.
5. Try it yourself: crack this code
The secret is 4 different digits. Here are the replies to four guesses:
- 1234: 0 bulls, 1 cow
- 5678: 2 bulls, 0 cows
- 5902: 3 bulls, 0 cows
- 5601: 3 bulls, 0 cows
Exactly one code fits all four. Hint: the first two replies give three of the four digits, and the last digit is 0 or 9.
Show the answer
The secret is 5602. The replies to 5678 and 5601 put a 5 first and a 6 second. Then 5902 needs three bulls: the 9 can’t be second, because the 6 is there, so the 5, the 0 in third place and the 2 in fourth must all be in place. Check it: 1234 gives 0 bulls and 1 cow (the 2); 5678 gives 2 bulls (the 5 and the 6); 5902 gives 3 bulls (the 5, the 0 and the 2); 5601 gives 3 bulls (the 5, the 6 and the 0).
Now make your own code and let a friend crack it. If you enjoy the deduction, how to get better at logic puzzles has habits that work for this kind of puzzle too.





