How to Play Bulls and Cows: Rules, Example and Strategy
Bulls and cows is a code-breaking game for two players. One player thinks of a secret number with all-different digits; the other guesses it. After each guess you learn how many digits are right and in the right place, and how many are in the code but somewhere else. Our two games show these clues in their own way: Number Guess with green and yellow dots, Protocol 4 with two numbers. This guide explains both, using the same example.
The rules
- The code maker picks a secret number with no repeated digits that does not start with 0, for example 4271. Number Guess offers three-, four- and five-digit codes; Protocol 4 codes are four digits long.
- The code breaker guesses a number of the same length, also with all-different digits.
- Every guess gets a clue: how many digits are in the right place, and how many are in the code but in the wrong place. On paper these are traditionally called bulls (right place) and cows (wrong place).
- When every digit is in the right place, the code is cracked.
- In the classic two-player game, both players set a code for each other and take turns; whoever cracks the other's code in fewer guesses wins.
With four different digits and no leading zero there are 4,536 possible codes.
Number Guess: green and yellow dots
Number Guess shows each clue as a row of dots, one dot for each digit of the code:
- Green: a right digit in the right place.
- Yellow: a right digit in the wrong place.
- Empty: a digit that is not in the code.
The dots are sorted, greens first and then yellows, so they do not line up with the digits you typed. Three green dots tell you that three digits are in place, but not which three: working that out is the game.
Example: the code is 4156 and you guess 4153. You get : three digits (4, 1 and 5) are in place, and 3 is not in the code.
Protocol 4: correct positions and correct digits
Protocol 4 answers each guess with two numbers:
- Correct positions (POS): digits that are right and in the right place.
- Correct digits (DIG): every digit of your guess that is in the code, including the ones already in the right place.
Same example: the code is 4156 and you guess 4153. Protocol 4 shows 3 correct positions, 3 correct digits. The two numbers are equal, so none of the right digits is out of place, and the fourth digit is not in the code.
For the number of right digits in the wrong place, subtract: correct digits − correct positions. In bulls-and-cows terms, correct positions are the bulls and that difference is the cows.
An example game
The secret code is 4271. Here is the same game as each app shows it:
| Guess | Number Guess | Protocol 4 | What it tells you |
|---|---|---|---|
| 1234 | 1 correct position · 3 correct digits | Three of 1, 2, 3 and 4 are in the code; one of them is already in place. | |
| 5678 | 1 correct position · 1 correct digit | Exactly one of 5, 6, 7 and 8 is in the code, and it is in place. So 9 and 0 are out. | |
| 4217 | 2 correct positions · 4 correct digits | All four digits are right (4, 2, 1, 7); two of them are in place. | |
| 4271 | 4 correct positions · 4 correct digits | Cracked in four guesses. |
Three strategies that work
1. Find the digits first, then their places
Open with 1234, then 5678. Count how many digits each guess found (all coloured dots in Number Guess, correct digits in Protocol 4): that tells you how many code digits are among 1–4, among 5–8 and, by subtraction, among 9 and 0. From there you only have to arrange a handful of digits.
2. Keep a grid of what each position cannot be
A guess with no green dots (0 correct positions in Protocol 4) tells you that every digit in it is in the wrong place. Write those down: a digit's position is often settled by elimination rather than by a lucky guess.
3. Only guess codes that could still be the answer
Before each guess, check it against every clue you have had so far. A guess that contradicts an earlier clue wastes a turn. Computer analysis has shown that every four-digit code can be cracked in at most seven guesses this way.
Play it on your phone
Number Guess is bulls and cows with green and yellow dots, for one or two players. Play a quick match, send a six-character invite code, or take turns at your own pace; solo games work offline. Codes can have three, four or five digits.
Prefer a hacker story? Protocol 4 uses the same deduction, with correct positions and correct digits, in real-time duels.
Frequently asked questions
Why is it called bulls and cows?
It is an old pen-and-paper game; the names are the traditional words for the two kinds of hit. A bull is a right digit in the right place, a cow is a right digit in the wrong place. In Number Guess, bulls are the green dots and cows are the yellow ones.
Why does Protocol 4 show 3 correct digits when 3 are already in place?
Because in Protocol 4 the correct digits count includes the digits in the right place. 3 correct positions and 3 correct digits means three digits are right and all three are already in place. Subtract the two numbers to get the digits that are right but misplaced.
Can digits repeat?
No. In Number Guess and Protocol 4, every digit in the code and in each guess is different, and a code never starts with 0.
What is the fewest number of guesses needed?
With a good strategy any four-digit code can be solved in at most seven guesses; most games take five or six.
What other names does this game have?
Bulls and cows is also called cows and bulls, 4-digit number guessing or Guess 4; Mastermind is the colour version. Protocol 4 started out as Guess 4.
Open Number Guess Open Protocol 4 Play Bulls and Cows in your browser