Play Bulls & Cows Online
Crack the secret 4-digit code using logic and deduction. Each guess tells you how many digits are correct and in the right place (Bulls) — and how many are correct but misplaced (Cows).
Created by Brian Hamilton
Enter your guess below
How to play Bulls & Cows
Work out the hidden code from the feedback on each guess.
- The code is 4, 5 or 6 digits with no digit repeated.
- A Bull is a digit that is correct and in the right position.
- A Cow is a digit that is in the code but in the wrong position.
- The reply tells you how many of each, never which digits earned them.
- You get ten guesses. Good play needs about five for a four-digit code and never more than seven.
Controls: tap the keypad or type digits, then press Enter to submit. Backspace deletes. A greyed-out key has been ruled out by your own answers; a green one is certain.
The feedback tells you how many, never which
Every guess comes back as two numbers: Bulls for digits in the right place, Cows for digits that are in the code but somewhere else. The whole difficulty of the game sits in what those numbers leave out. “One Bull, two Cows” tells you three of your four digits are in the code. It does not tell you which three, and it does not tell you which one is already home.
The codes on this page have no repeated digits
That is worth stating plainly, because it changes the arithmetic. The code is drawn by shuffling the digits 0–9 and taking the first few, so a four-digit code is one of 5,040 possibilities rather than 10,000, and no digit ever appears twice. Checked over 200,000 generated codes, all 5,040 turn up, no code contains a repeat, and no digit favours any position by more than 1.8%.
| Code length | Possible codes | Average guesses | Worst seen |
|---|---|---|---|
| 4 digits | 5,040 | 5.23 | 7 |
| 5 digits | 30,240 | 5.84 | 8 |
| 6 digits | 151,200 | 6.48 | 9 |
Notice how slowly that grows. Thirty times as many six-digit codes as four-digit ones, and good play needs barely one more guess — because each answer cuts the field by a large factor rather than a fixed amount. All three lengths finish inside the ten guesses the game allows, with room to spare.
A first guess that splits the field
The opening guess cannot be wrong, exactly, but it can be wasteful. What you want is the guess whose possible answers divide the 5,040 codes into the most even groups, because the size of the group you land in is what you have left to work through.
There are only 14 distinct answers a four-digit guess can come back with — 0 Bulls 0 Cows through to 4 Bulls. That sets a floor on the whole game: no strategy whatsoever can average better than log14(5,040) ≈ 3.2 guesses. Good play measures at 5.23, so there is a real gap between what is achievable and what is information-theoretically conceivable — the answers are not evenly sized, and never can be.
A concrete habit worth adopting: after each answer, ask what the next guess would tell you in the worst case, not the best. A guess that might crack the code but usually teaches you nothing is a worse guess than one that always halves the field.
Working the constraints, not the digits
Zero and zero is the best answer you can get early. Zero Bulls and zero Cows on a four-digit guess removes four digits from consideration at once, leaving six. It feels like failure and it is the single most informative reply in the game.
The total matters before the split does. Bulls plus Cows tells you how many of your digits are in the code at all — settle that before worrying about positions. Two guesses that share three digits and differ in one isolate that one digit precisely.
Rotate, do not replace. Once you know four digits are all in the code, the remaining work is a permutation puzzle, and the fastest way through it is to move a few digits at a time and read the change in the Bull count. Swapping two digits and gaining a Bull tells you exactly which of them moved home.
What the numpad does and does not tell you
The digits on the keypad grey out when they are ruled out, and turn green when they are certain. Those marks are deduced from the answers you have been given — the game keeps track of every code still consistent with your guesses, and marks a digit only when all of them agree. It is bookkeeping, not a hint: nothing appears that you could not have worked out from the numbers on the screen.
It also means the marks stay silent when the position is genuinely ambiguous. After a single four-digit guess it settles about a third of a digit on average — usually nothing at all. Late in a game, once the constraints bite, it can pin most of the keypad at once.
Where solvers go wrong
Guessing something already ruled out. The commonest waste is a guess that contradicts an earlier answer, which cannot possibly be the code and so teaches nothing. Before committing, check the guess against every answer so far.
Chasing a single digit. Testing one digit per guess is safe and slow. With ten guesses and an average requirement of five, there is no need to be cautious — a guess that could resolve three unknowns at once is worth the risk.
Forgetting the no-repeat rule. Because the code never repeats a digit, every digit you confirm removes a possibility from all the other positions too. That constraint does a lot of work and is easy to leave on the table.
What was verified on this page
The feedback function was checked against an independently written one on every one of the 25,401,600 possible guess-and-code pairs for a four-digit code, and on all 518,400 pairs for three digits. They agree everywhere, so the Bull and Cow counts this page reports are correct.
One thing was wrong and has been fixed. The keypad colouring used to be computed by looking at the answer rather than by reasoning from the feedback. It would grey out exactly those digits missing from the code and highlight exactly the ones already in place — facts the Bull and Cow numbers had not revealed. Measured over 3,000 games, it stated 2.82 digits after a single four-digit guess where the feedback justified 0.31. It now tracks the consistent codes properly and states only what follows, verified across 2,893 guesses: it never asserts anything false, says nothing before the first guess, and never loses the true code from the set it is reasoning over.
Bulls and Cows, Mastermind, and which is harder
Mastermind is the same idea with coloured pegs, and it usually allows repeats, which makes it a different problem: 1,296 possibilities for four pegs in six colours, famously crackable in five guesses by Knuth's 1977 analysis. Bulls and Cows with no-repeat digits has four times as many codes and needs about five and a quarter guesses. More possibilities, but each answer is sharper — the no-repeat rule that enlarges the field also constrains it.
The game is much older than either analysis and was played with pencil and paper long before it was computerised; the digit version is the one that spread, because it needs nothing but two players and something to write on.
More puzzles like this
If you like narrowing things down by elimination, try these: