Number Baseball rules and strategy

You work out a secret four-digit number from only two numbers: strikes and balls. The rule takes three lines, but how you narrow it down is where skill shows. This page goes in order, from what a beginner should read first to exactly how far candidates shrink, counted by hand.

What kind of game is Number Baseball

One side picks and hides a number, and the other tries to guess it. The guesser calls out a four-digit number, and the side holding the secret answers with only two counts. The exact answer is never given away directly. Stacking those two counts over several rounds is the entire game.

The name and terms borrow from baseball; in English it's also known as Bulls and Cows. It needs nothing but paper and pencil, so it predates computers by a long way. It looks like it involves numbers, but nothing is ever added or subtracted, so the game works just as well with ten colors in place of digits.

You can count exactly how much luck is involved. A four-digit number with no repeated digits has ten choices for the first digit, nine remaining for the second, eight for the third, and seven for the fourth, for 5040 total. Guessing blind and getting it right on the first try is a 1-in-5040 shot, but narrowing with logic usually finishes in five or six tries, as shown below. That gap is what makes the game fun.

Basic rules

What the secret number looks like

The secret number picks four digits from 0 through 9 and lines them up. The four digits must all be different, so no digit repeats. A leading zero is allowed, so a number like 0473 can be the answer. Forgetting that rules out close to a tenth of all candidates right from the start.

Strikes and balls

Calling out four digits returns two counts. A strike is a digit that's both correct and in the right position; a ball is a digit that's in the secret number but in a different position. No single digit is ever counted as both a strike and a ball. So strikes plus balls always equals how many of your four called digits actually appear somewhere in the secret number. That one fact matters a great deal later.

Out and home run

Zero strikes and zero balls is an out: none of the four digits you called are in the secret number at all. Four strikes is a home run, and you win. It's also possible to get every digit right but every position wrong, zero strikes and four balls, which is in fact almost there.

How this app works

From here on, this section covers what this specific app does. Number Baseball implementations vary in these details, so reading this once should save you some confusion.

One secret a day, the same for everyone

The secret number is built from that day's date. The date string is folded into a single number, which is used to shuffle 0 through 9 and cut the first four. Anyone who visits on the same day gets the same secret number, and a new puzzle opens after midnight. The clock is your device's date, so the switch happens at a different moment if you're in a different time zone.

Both generating the number and judging guesses happen entirely in your browser. The secret number is never sent down from a server, and the digits you call are never sent to one. No account is needed.

Ten tries

You get up to ten guesses per round. A home run ends it on the spot; using all ten without one closes the round and reveals the answer on screen. The remaining count keeps showing above the input box. Ten is a fairly generous number: as section 5 counts, playing with logic alone finishes within eight tries even in the worst case.

How input is filtered

Type four digits in a row into the box. Anything that isn't a digit is rejected outright, and a fifth character gets cut off. If the four digits you filled in include a repeat, a message appears saying they must all be different and the guess button stays disabled. Pressing Enter also submits. There's no restriction on the order you call numbers; you're free to throw whatever you like whenever you like.

What isn't saved

This part is worth stating plainly. Your guesses so far live only on screen and are never saved anywhere. Refreshing or closing and reopening the tab erases your history and starts over from scratch. The secret number still comes from the date, so it stays the same on the same day, but any hints you've already worked out only live in your own head. It's best to leave the tab open while you're in the middle of a round.

What's missing is worth noting too. There is no hint button that reveals the answer, no undo to take back a guess, and nothing that counts remaining candidates for you. There's no timer either.

What the share text includes

When a round ends, a button appears to copy your result. The copied text includes the date, how many tries it took, and, for each round, only how many strikes and how many balls as symbols. Neither the secret number nor your guesses are included. It's built so that sending it to a friend who hasn't played today yet won't leak the answer.

Basic tips

Any first guess is the same

Many people agonize over their opening guess, but the short answer is: don't bother. Running all 5040 possible first guesses and counting how each one splits the 5040 candidates produces an identical result every time. Starting with 0123 or with 5907 leaves exactly the same number of remaining candidates for each possible outcome, digit for digit. With no information yet, no digit is labeled differently from any other. Throwing your lucky number or your birthday first costs you nothing.

How much the first result narrows things down

Here's the table straight from that calculation: every possible outcome for a first guess, and how many secret-number candidates remain for each. They add up to 5040.

First outcomeCandidates left
0 strikes 0 balls (out)360
0 strikes 1 ball1,440
0 strikes 2 balls1,260
0 strikes 3 balls264
0 strikes 4 balls9
1 strike 0 balls480
1 strike 1 ball720
1 strike 2 balls216
1 strike 3 balls8
2 strikes 0 balls180
2 strikes 1 ball72
2 strikes 2 balls6
3 strikes 0 balls24
4 strikes (home run)1

The most common outcome is 0 strikes 1 ball, happening 1440 times out of 5040. Averaged across every outcome, 931.41 candidates remain after one guess, roughly a fifth of the original 5040. That still looks like a long way to go, but the second guess onward narrows things down much faster.

Look at the sum first

This is the first habit that separates beginners from experienced players. Don't read strikes and balls separately; add them first. That sum is exactly how many of your four called digits are in the secret number. 1 strike 2 balls means three digits are in, and one isn't. You don't yet know which digits those are, but the count is settled. Positions can wait until after that.

An out isn't a waste

A result with nothing matching at all feels like a dud, but it's actually one of the strongest narrowing results you can get. If you call 0123 and get an out, the secret number is made up entirely from the six digits 4 through 9, leaving only 360 candidates, exactly the count of ordered picks of four from six. Compared to the post-first-guess average of 931.41, an out narrows things to about a third of that. If you get an out, mark those four digits off for certain and pick only from the remaining six from then on.

Keep eliminated digits visible

This app doesn't count candidates for you, and your guess history disappears on refresh. You'll have a much easier time writing down 0 through 9 on paper and crossing off digits as they're ruled out. A single line in a notes app is enough. Doing it all in your head tends to burn two or three of your ten tries just re-confirming things you already knew.

Advanced tips

Every number below comes from actually running all 5040 possibilities, not an estimate. Each is the result of scoring one outcome at a time and adding up what remains.

Overlap your second guess by one or two digits

Fixing the first guess as 0123, we tried all 5040 possible second guesses and computed the average number of remaining candidates for each. Grouping by how many digits overlap with the first guess splits the results clearly.

A common piece of advice is to follow 0123 with 4567 to sweep all eight digits at once. That's not bad, but it isn't optimal. Using zero overlap averages 216.1 candidates no matter which guess you pick, but keeping two digits from your first guess and moving their positions, a number like 1045, brings that down to 167.0. The reason is simple: re-throwing overlapping digits with their positions swapped asks two questions at once, which digits are in and where they are.

Shuffling the same four digits is wasteful

Following 0123 with 1032, keeping the same digits and only shuffling positions, was the worst option, averaging 495.8 remaining candidates, more than double a non-overlapping guess. You learn nothing new about which digits are in, because you already called all four. This move belongs to the endgame, once you've already identified every digit and only positions remain, not the opening.

When one result drops candidates below ten

A few rows in the earlier table are worth a closer look. A result of 0 strikes 4 balls leaves exactly nine candidates, because all four digits are correct and every single position is wrong. For 0123, those nine are 1032, 1230, 1302, 2031, 2301, 2310, 3012, 3201, and 3210. A result of 2 strikes 2 balls leaves only six, since it's just a matter of which two positions are correct and swapping the other two. 3 strikes 0 balls narrows to 24, covering every choice of which one of the four positions is wrong paired with any of the six remaining digits to fill it.

Once you know all four digits, three strikes can't happen

Once you've confirmed which four digits are in the secret number, only their order is left, 24 possibilities. Calling any one of them can only produce one of four outcomes: 0 strikes (9 ways), 1 strike (8 ways), 2 strikes (6 ways), or the home run (1 way). Three strikes is impossible here, because if three positions are correct, the fourth position is automatically correct too. So at this stage, landing 2 strikes narrows candidates to six, and one more swap of two positions in the next guess usually finishes it.

A worked example

Talking about it in the abstract doesn't give you a feel for it, so here's a full round counted out. Starting with 0123 and getting 1 strike 1 ball narrows 5040 down to 720. Following with 2345 and getting 1 strike 1 ball again brings that to 92. A third guess of 4567 getting 0 strikes 2 balls leaves just 28. Three guesses turned 5040 into 28. One or two more good guesses from here locks in the answer.

Pick the guess that minimizes your worst case

There's one standard for choosing your next guess among the remaining candidates: look at how that guess splits the candidates by outcome, and pick the guess whose largest resulting group is the smallest. This optimizes for the worst case, not the average. Running this strategy to completion for every one of the 5040 possible secret numbers finishes in 5.32 tries on average, with the longest case taking eight. 109 of the 5040 secret numbers finish in three tries; five tries is the most common case at 2071; only three of the 5040 secret numbers take as long as eight tries. That's why ten tries turns out to be generous. You can't run this exact computation in your head, but simply aiming to split the remaining candidates roughly in half each time gets you most of the way there.

Common sticking points

Nothing but balls keeps coming up

Lots of balls actually means you've picked the right digits but put them in the wrong spots, which is a good sign, not a bad one. Throwing in new digits here only muddies the information you've already gathered. Keep the digits you're confident are in and rearrange their positions. If a guess gains a strike and loses a ball, the position you just moved into is correct.

You know the digits but can't place them

You're down to 24 candidates. Don't flip everything at once; swap just two positions at a time and watch how the strike count moves, since that movement is the answer. If it goes up by 2, both newly placed positions are correct. If it goes up by 1, only one of them is. If it stays the same, neither of the original two positions was right nor were the swapped positions, so those two digits belong in the other two slots. If it drops by 1, one of the original two positions was actually correct; if it drops by 2, both were correct and you disturbed them for nothing. Those five outcomes cover every case, so there's no ambiguity. Moving three or more positions at once, though, makes it impossible to tell which move caused the change.

Forgetting zero

This is the most common mistake. A leading zero is a valid answer, but many players unconsciously only call digits 1 through 9. Excluding zero from consideration throws away 2016 of the 5040 candidates right from the start. Including a zero in your first guess sidesteps this problem entirely.

Asking something you already know

Check once before you throw: does the guess you're about to make actually fit everything you've learned so far? If it mixes in a digit you've already ruled out with an out, or breaks a position you've already confirmed, that guess teaches you almost nothing no matter what comes back. Picking only from guesses that could actually be the answer, given what you already know, saves you two or three tries on its own.

Your history disappeared

Refreshing clears your guess history and starts the round over. Today's secret number stays the same, though, so anything you've already worked out is still valid. If you wrote it down on paper, keep using that and carry on. If you didn't write anything down, you're effectively starting from scratch. If a round looks like it'll take a while, write your guesses and results down somewhere.

Missed today's round

You can replay puzzles from the last 14 days with "Past rounds" on the home page. Since the secret number is derived from that day's date, the same date always gives the same puzzle. Puzzles older than 14 days don't open, and a new puzzle that no one has solved yet opens at midnight tomorrow.