Bulls and Cows
Practice · crack a 4-digit code, no repeated digits
Code length
Your guesses and their clues will appear here. Bulls: right digit, right place. Cows: right digit, wrong place.
Enter 4 different digits. 0 can come first.
Think of a 4-digit code with no repeated digits (0 can come first) and write it down. Then press Start.
Bulls: right digit, right place
Cows: right digit, wrong place
Enter your code to see whether every answer was right. It stays on this device.
Play Bulls and Cows online
Bulls and Cows is a code-breaking game of pure logic. The computer picks a secret code of different digits and you try to work it out. Every guess is scored with two numbers: bulls, digits that are right and in the right place, and cows, digits that are in the code but somewhere else. Put the clues together and you can deduce any 4-digit code in a handful of guesses. On this page you can play unlimited practice codes of 3, 4 or 5 digits, take on the daily code that everyone gets on the same day, mark digits in or out as you deduce them, ask for a hint, or turn the tables and let the computer guess a code you're thinking of. It runs in your browser with nothing to install and no account.
How to play
- Choose a code. Practice gives you a fresh code whenever you like, in 3, 4 or 5 digits. Daily is one 4-digit code for everyone, once a day.
- Enter a guess. Tap the keypad or type digits on a keyboard. Every digit must be different, and 0 can come first. Press Guess or Enter.
- Read the clue. Each guess is listed with its bulls and cows, shown as filled dots for bulls and rings for cows.
- Take notes. Turn on Notes and tap a digit to mark it out (not in the code), again to mark it in, and a third time to clear it. Marked digits are coloured in your guess list too.
- Crack it. Keep going until you score all bulls. Hint fills in a guess that fits every clue so far, and Give up reveals the code (it counts as a loss).
- Challenge a friend. After a practice code, Share sends your result as a grid of bulls and cows plus a link that gives your friend the very same code to crack.
A worked example
Say the secret is 4271 and you open with 0123. Two of those digits, 1 and 2, are in the code but both in the wrong places, so the clue is 0 bulls, 2 cows. Next you try 4567: the 4 is exactly where it should be and the 7 is in the code somewhere else, so that's 1 bull, 1 cow. Add it up: two digits from 0–3 and two from 4–7 make all four, so 8 and 9 are out, and only 168 of the 5,040 codes still fit both clues. Notice that neither clue says which digits scored. Working that out, one careful change at a time, is the whole game.
Strategy tips
- Open with 0123, then 4567. Two guesses cover eight digits. Add the bulls and cows from both and subtract from 4: that's how many of 8 and 9 are in the code.
- Separate "which" from "where". Bulls plus cows tells you how many of your digits are in the code. Settle which digits first, then work on their positions.
- Treat 0 bulls, 0 cows as a gift. Every digit in that guess is out. Mark them out, then reuse them as known blanks to test one new digit at a time.
- Change one thing at a time. Swap just two digits between guesses and watch the bulls go up or down to pin those two positions.
- Make late guesses that could be the answer. Early guesses can be pure information, but from the fourth or fifth on, each guess should fit every clue so far. Hint shows one that does.
- Count what's left. Turn on "Show codes left" in Stats to see how much each guess narrowed things down; a good guess often cuts the possibilities by more than half.
Bulls and Cows by the numbers
| Code length | Possible codes | What to expect |
|---|---|---|
| 3 digits | 720 | A quick warm-up. The computer averages about 5 guesses. |
| 4 digits | 5,040 | The classic. Always solvable in 7 guesses with perfect play; the best possible average is about 5.21. |
| 5 digits | 30,240 | A real test of bookkeeping. Notes help a lot here. |
Each first guess splits the 5,040 four-digit codes into groups by the clue it would get. After 0123, for example, the most common answer is 0 bulls and 1 cow, which still leaves 1,440 codes, while 0 bulls and 0 cows leaves just 360. That's why a "bad" clue is often the most useful one.
Let the computer guess your number
Switch to Computer guesses, think of a code and write it down, then score each of the computer's guesses with bulls and cows. It keeps a list of every code that still fits your answers and picks the guess whose worst possible answer leaves the fewest codes standing, the same minimax idea Donald Knuth used for Mastermind. In tests on all 5,040 four-digit codes it averaged about 5.3 guesses and never needed more than seven. Impossible combinations, such as 3 bulls and 1 cow, can't be entered, and if your answers contradict each other it tells you, lets you undo, and can check each answer against your code.
A little history
Bulls and Cows began as a pencil-and-paper game and is older than Mastermind, the coloured-peg board game from the early 1970s. It was also one of the first games written for computers: a version called MOO ran at the University of Cambridge before the summer of 1970 and was later carried to other systems, including early Unix. The same idea lives on in word games: Word Guess scores letters the way Bulls and Cows scores digits. For more number puzzles, try Guess the Number, Sudoku or Math Blitz.
Frequently Asked Questions
How do you play Bulls and Cows?
One player picks a secret code of different digits, usually four, and the other tries to guess it. Every guess gets a clue: a bull for each right digit in the right place and a cow for each right digit in the wrong place. Use the clues to narrow it down until you score all bulls.
What's the difference between a bull and a cow?
A bull is a digit that is in the secret code and in the same position as in your guess. A cow is a digit that is in the code but in a different position. Each digit you guess earns at most one of the two, and the clue never says which digits earned them.
How many guesses does it take to solve Bulls and Cows?
With four digits, every one of the 5,040 possible codes can be cracked in seven guesses or fewer, and the best possible average is about 5.21 guesses. Solving in six or seven is a solid result; four or fewer usually takes some luck as well.
Can the secret code start with 0?
Yes. Any digit from 0 to 9 can be in any position, as long as no digit repeats. That gives 720 possible 3-digit codes, 5,040 4-digit codes and 30,240 5-digit codes.
Can I guess a number with repeated digits?
No. Guesses follow the same rule as the code: all digits different. The keypad greys out digits already in your guess, and a guess you've already tried doesn't count again.
What does 0 bulls and 0 cows mean?
None of the digits you guessed are in the code. It's one of the most useful clues you can get, because it rules out several digits at once. Mark them out with Notes so you don't use them by mistake, or use them as known blanks to test other digits.
What's a good first guess in Bulls and Cows?
Every first guess is equally likely to be right, so treat it as information gathering. A common opening is 0123 followed by 4567: together they show how many code digits come from each group, which tells you how many of 8 and 9 are in the code.
Can the computer guess my number?
Yes. Choose Computer guesses, think of a code and score each guess with bulls and cows. It keeps every code that fits your answers and picks the guess that splits them most evenly, usually finishing in about five guesses. If your answers contradict each other it says so, and you can enter your code to see which answer was off.
What is the daily code?
A 4-digit code that is the same for everyone on the same day and changes at midnight your time. You get one go at it, so it's a fair way to compare with friends: Share sends your result as a grid of bulls and cows without giving the code away.
Can I send a friend the same code?
Yes. When you finish a practice code, Share includes a link that opens exactly that code for whoever taps it, along with your result as a grid of bulls and cows that doesn't give the digits away. For a code everyone gets, play the daily.
Is Bulls and Cows the same as Mastermind?
They're close relatives. Bulls and Cows is an older pencil-and-paper game played with digits; Mastermind, sold from the early 1970s, uses coloured pegs and usually allows repeated colours. The feedback works the same way, and Wordle's green and yellow tiles are the same idea applied to words.
Are my results saved?
Yes, on this device only. Your games in progress, notes and statistics for each code length and the daily code are kept in your browser's local storage. Nothing is uploaded and there's no account.
More games to play
Free, browser-based, and instant — no installs or accounts.