Bulls and Cows

Bulls and Cows is a code-breaking game: the computer hides four different digits and you have ten guesses to find them. Each guess is scored in bulls — right digit in the right place — and cows — right digit in the wrong place. Against the code 4271, a guess of 1234 scores one bull (the 2) and two cows (the 4 and the 1). A Colours mode plays the same game with six colours and repeats allowed.

Numbers · guess 1 of 10

Notes · tap once to rule out, twice to confirm

Guesses0/10ModeNumbersTime0:00Game#0

New game hides a fresh code in the mode you last chose — Numbers, four different digits, or Colours, four pegs from six colours — and the three-dot menu switches mode and holds today’s shared code. Hint fills in a guess that fits every score so far; press Enter to play it. Tap a digit in the notes strip once to rule it out and again to mark it confirmed.

Your statistics · Numbers

Played
0
Won
0
Win rate
0%
Streak
0
Best streak
0
Best time
—
Fewest guesses
—

How a guess is scored

Bull — the right digit in the right place.
Cow — a digit in the code, but in a different place.

Today’s code

Everyone who opens today’s game gets the same secret code — one for Numbers and one for Colours — and it changes at midnight UTC.

Keyboard

0 – 9
Type a digit
Backspace
Delete the last one
Enter
Play the guess
H
Hint
Shift + key
Cycle its note
N
New code
F
Full screen
Codes
5,040 in Numbers · 1,296 in Colours
Guesses
10 per code
Scored in
Bulls and cows
Daily
One shared code a day

How do you play Bulls and Cows?

The computer hides a code of four different digits, 0 to 9 — a leading 0 is allowed, so 0123 is a code like any other. You type a guess of four different digits and press Enter, and it comes back scored: a bull for every digit that is right and in the right place, and a cow for every digit that is in the code but somewhere else. A digit is never both. Four bulls cracks the code; ten guesses without them and the code is shown.

Guesses scored against the code 4271
GuessBullsCowsWhy
123412The 2 is in place; the 1 and the 4 are in the code, elsewhere
569000None of 5, 6, 9 or 0 is in the code
741204All four digits are right and none is in place
427530The 4, 2 and 7 are in place; there is no 5
427140Cracked

Colours mode is the same game with four pegs from six colours — red, yellow, green, blue, purple and white — and repeats allowed, which makes 1,296 possible codes instead of 5,040. Every colour also carries its own shape, a dot, a triangle, a square, a diamond, a star or a cross, so no two pegs rely on colour alone.

What does the first score tell you?

Every opening of four different digits is the same position with the digits renamed, so the first guess is yours to choose freely — and the score it gets splits the 5,040 codes into groups of very different sizes. These are the exact counts for any opening, the same whether you start with 0123 or 9876.

What a first guess can score, out of 5,040 codes
ScoreCodes still possibleShare
0 bulls, 0 cows3607.1%
0 bulls, 1 cow1,44028.6%
0 bulls, 2 cows1,26025.0%
0 bulls, 3 cows2645.2%
0 bulls, 4 cows90.2%
1 bull, 0 cows4809.5%
1 bull, 1 cow72014.3%
1 bull, 2 cows2164.3%
1 bull, 3 cows80.2%
2 bulls, 0 cows1803.6%
2 bulls, 1 cow721.4%
2 bulls, 2 cows60.1%
3 bulls, 0 cows240.5%
4 bulls10.02%

Two things stand out. The likeliest first score is a single cow — 1,440 codes in 5,040 — and it tells you the least. And nothing at all is good news rather than bad: 0 bulls, 0 cows happens for 360 codes, and it rules out four of the ten digits in one go, leaving only codes built from the other six. One score never appears at all: three bulls and one cow is impossible, because if three digits are in place and the fourth is somewhere in the code, the only place left for it is its own.

How are repeated colours scored?

In Colours a code can hold the same colour more than once, and so can a guess, which is exactly where careless scoring goes wrong. The rule is the min-count rule: for each colour, the number of matches is the smaller of how many that colour appears in the code and how many in the guess. Add those up over all six colours, and whatever is not a bull is a cow. Each peg of the code pays out once and only once, and a bull always takes its peg before a cow can.

Repeated colours, scored correctly
CodeGuessBullsCowsWhy
Red Green Green BlueGreen Green Red Red12The code has one Red, so the two Reds in the guess earn one match between them
Red Red Yellow YellowYellow Yellow Red Red04Every peg is matched and none is in place
Blue Yellow Green RedRed Red Red Red10The code's one Red is already paid out as the bull
White White Purple RedPurple White White White12Two Whites to give: one in place, one elsewhere; the third White scores nothing

The first row is the trap. A scorer that checks each peg of the guess against the code on its own sees two Reds that are both "in the code" and hands out three cows; the right answer is two, because the code has only one Red to give. In Numbers no digit repeats, so the same rule simply counts the digits that are in the code but out of place.

How good is the hint?

Press Hint and the board fills in a guess that fits every score so far — a code that could itself be the answer. Among all the codes that still fit, it picks the one expected to leave the fewest standing: it imagines playing each candidate, sorts the codes that remain by the score each would give it, and takes the candidate whose groups come out smallest on average. It never looks at the answer, which is what makes it fair to measure by letting it play every code there is.

Following the hint on every turn, against every code
ModeCodesAverage guessesMost guessesWithin five guesses
Numbers5,0405.328, for 3 codes56.0%
Colours1,2964.426, for 43 codes96.7%

Perfect play does a little better, and it is known exactly. In the four-digit game any code can be cracked within seven guesses, and the lowest possible average — found by Tetsuro Tanaka of the University of Tokyo in 1996 — is 26,274 guesses over the 5,040 codes, about 5.21 each. For six colours and four pegs, Donald Knuth showed in 1977 that five guesses always suffice, and Koyama and Lai found the lowest average in 1993: 5,625 guesses over the 1,296 codes, about 4.34. The hint gives away about a tenth of a guess to those results because it only ever proposes a code that could be the answer, where a perfect player will sometimes spend a guess on one that cannot, purely to split the field.

Where does Bulls and Cows come from?

It is a pencil-and-paper game, and an old one — it may date back a century or more, played by two people who each write down a secret number and take turns guessing the other's. It was also one of the first games anybody played on a computer: in 1968 Frank King wrote a version called MOO for the Titan computer at Cambridge University, and in 1970 J. M. Grochow wrote another at MIT for the Multics operating system.

The coloured-peg form is a later boxed take on the same idea, with colours in place of digits and repeats allowed. This page plays both under the game's own traditional name, with the rules people played on paper. If you like reasoning from feedback about a hidden answer, Word Guess does it with letters and Minesweeper with numbers on a grid.

How do you get better at bulls and cows?

  • Welcome a score of nothing0 bulls, 0 cows on a Numbers opening happens for 360 of the 5,040 codes and clears four digits with one guess: everything left is built from the six you did not play. It is the most useful bad-looking score in the game.
  • Settle which digits before where they goBulls plus cows says how many of your four digits are in the code, whatever their order. Pin down the set first — swapping one or two digits between guesses shows which ones count — and only then spend guesses on positions.
  • Change one thing at a time to find a bullWhen a guess scores a bull, keep three digits where they are and move or change the fourth. If the bull disappears you have found it; if it stays you have ruled out a position. One change per guess keeps every score readable.
  • Play codes that could be the answerA guess that fits every score so far can win outright, and it is what the hint always proposes. Played that way on every turn, each of the 5,040 Numbers codes falls within eight guesses, 5.32 on average.
  • Open Colours with a pair and two singlesFollowed by the hint's own choices, an opening of Red Red Yellow Green cracks the 1,296 codes in 4.42 guesses on average, against 4.45 for four different colours, 4.46 for two pairs and 4.56 for three of one colour.

Bulls and Cows questions people ask

Can digits repeat in Bulls and Cows?
Not in Numbers: the code is four different digits and so is every guess, which is what makes 5,040 codes (10 × 9 × 8 × 7). In Colours they can — a code like Red Red Blue Red is allowed — and repeats are scored with the min-count rule, each peg paying out once.
Can the code start with a zero?
Yes. 0123 is as much a code as 9876, and every one of the 5,040 arrangements of four different digits is equally likely to be the one hidden.
Is three bulls and one cow possible?
No. If three digits are right and in place and the fourth digit is in the code too, the only position left for it is its own, which would make it a fourth bull. It is the one score in either mode that can never appear.
What happens if I repeat a guess?
It is refused without costing a guess. The same guess against the same code can only score what it scored before, so playing it again could not tell you anything new.
Is there a daily Bulls and Cows code?
Yes. Today's code in the three-dot menu gives everyone the same secret for the day — one for Numbers and one for Colours — and it changes at midnight UTC. Cracking it marks the day on the daily games page.
Does taking a hint cost anything?
No guesses: a hint only fills in the next guess, and you still spend a guess to play it. The number of hints you took is shown with the result and in the share text, so a solve without help reads differently.

The rules in six lines

  1. 1The computer hides a codeFour different digits from 0 to 9 in Numbers, a leading zero allowed, or four pegs from six colours in Colours, where a colour may repeat.
  2. 2Every guess is scored in bulls and cowsA bull is a right digit or colour in the right place; a cow is one that is in the code but in a different place.
  3. 3Guess four different digitsIn Numbers every guess must use four different digits too. A repeated digit is refused as you type it and never costs a guess.
  4. 4Count repeated colours onceIn Colours each peg of the code can be matched only once, bulls first: two Reds in a guess against one Red in the code earn one match between them.
  5. 5Crack it within ten guessesFour bulls wins. If the tenth guess still falls short the game ends and the code is shown, so you always see what you were chasing.
  6. 6Keep notes, and take a hint when stuckTap a digit or colour in the notes strip to rule it out or confirm it. Hint fills in a guess that fits every score so far.

The long version, with worked examples and the questions beginners actually ask, is on how to play bulls and cows.

Put Bulls and Cows on your own site

The board runs in an iframe with no tracking, no cookies and no sign-up. Paste this wherever you want it. See all the embeddable games for the rest.

<iframe src="https://www.cardgamenook.com/embed/bulls-and-cows" width="100%" height="620" style="border:0;border-radius:10px;max-width:900px" title="Bulls and Cows — free online" loading="lazy"></iframe>
<p style="font:14px system-ui;margin:6px 0 0"><a href="https://www.cardgamenook.com/bulls-and-cows">Play Bulls and Cows</a> at Card Game Nook</p>