Birthday Problem Calculator
Twenty-three people is enough for a shared birthday to be more likely than not, which almost nobody believes on first hearing. The reason it feels wrong is that people count their own comparisons rather than all of them: twenty-three people make 253 pairs. The same arithmetic decides how many random IDs you can issue before a duplicate is likely, which is where it stops being a curiosity.
What this generator does
Computes the exact probability that at least two of a number of independent draws land on the same value. It works for the classic 365-day case and for any space size, which is the version that matters in practice: the same formula tells you how many random six-character codes you can issue before a duplicate becomes likely. It also shows the threshold counts — where the chance passes 1%, 50% and 99% — because those are what actually inform a decision.
How to use this tool
- Set how many distinct values are possible — 365 for birthdays, or the size of your ID space.
- Set how many are drawn.
- Press Calculate.
- Read the chance of at least one repeat, and the table of how it grows.
Understanding the controls
- Possible values
- The size of the space being drawn from. 365 gives the classic problem; a six-digit code gives a million; a short random string gives whatever its alphabet and length allow. The answer scales with the square root of this, not with the number itself, which is the surprising part.
- How many are drawn
- The number of people, IDs or codes. The chance of a repeat rises much faster than most people expect because every pair is an opportunity, and pairs grow quadratically.
Worked examples
- The famous one
- 23 people: 50.7% chance two share a birthday.
- How fast it rises
- 50 people: 97%. 70 people: 99.9%.
- Random six-digit codes
- Issue 1,000 from a million and a duplicate is about 39% likely.
- Why the square root matters
- Collisions become likely at roughly the square root of the space, not half of it.
Common use cases
- Working out how many random IDs can be issued before a collision is likely
- Sizing a random token or short code so duplicates stay improbable
- Teaching the birthday paradox with the numbers on screen
- Checking whether a random-code scheme is large enough for its expected volume
- Understanding why hash collisions arrive far sooner than hash length suggests
How this generator works
The chance of at least one repeat is computed as one minus the chance of no repeat, which is the only tractable direction — counting the collision cases directly would need inclusion-exclusion over every subset. The chance that all draws are distinct is a falling factorial over a power: the first draw can be anything, the second must avoid one value, the third must avoid two, and so on. Both are computed as exact integers and divided only at the end, so tiny and near-certain probabilities are equally accurate rather than collapsing to zero or one.
Randomness and fairness
Nothing is drawn and nothing is simulated. The result is exact arithmetic on the numbers entered, so identical inputs always give an identical answer.
For how randomness is produced across the whole site, see how Generate Random works.
Assumptions this tool makes
- Draws are independent and every value is equally likely, so no value is more popular than another.
- A repeat means any two draws matching, not a match against a particular value chosen in advance.
Limitations and good to know
- It assumes every value is equally likely and every draw independent. Real birthdays are not quite uniform, which makes real-world collisions slightly more likely than the model says, not less.
- It answers 'at least one repeat', not 'a repeat of my value'. The chance somebody shares your specific birthday in a room of 23 is about 6%, which is a different and much smaller number.
- Leap years are ignored. Including 29 February changes the classic answer by a fraction of a percent.
- For cryptographic sizing it gives the mathematics only. Whether a scheme is secure depends on far more than collision probability.
Common mistakes
- Comparing everybody against yourself
- The question is whether any two people match, not whether anybody matches you. Twenty-three people make 253 pairs, and it is the pairs that drive the answer.
- Assuming a large ID space makes duplicates impossible
- Collisions become likely near the square root of the space. A million possible codes means trouble around a thousand issued, not around half a million.
- Using this to argue a coincidence was meaningful
- The lesson runs the other way. Coincidences of this kind are far more likely than intuition suggests, which is a reason to expect them rather than to read anything into them.
Practical tips
- When sizing random codes, work back from your expected volume: pick the space so the collision chance at your ceiling is somewhere you are comfortable, and remember that is roughly volume squared over space.
- If duplicates would be costly, do not rely on probability at all. Check for collisions on insert — the arithmetic tells you how often you should expect to have to.
- The 1% threshold is usually the useful one for engineering. The 50% figure is the one that makes the point in a classroom.
Troubleshooting
- The answer seems far too high
- That is the paradox rather than an error. Check the pair count: n people make n(n−1)/2 comparisons, which grows quadratically and gets large much faster than n does.
- I need the chance of matching one specific value
- That is a different, much smaller calculation: one minus (1 − 1/values) raised to the number of draws. This tool answers the any-two-match question.
Privacy and your data
The space size and the number of draws are the only inputs, and both stay in your browser. That matters a little more here than on a plain calculator: the size of an internal ID space is a detail about a system somebody may not want to disclose, so it is never transmitted, never stored and never written into the page address. Analytics records only that the calculator ran.
Frequently asked questions
- Why is 23 the answer for birthdays?
- Because 23 people make 253 pairs, and each pair has roughly a 1-in-365 chance of matching. Multiply that out properly — as one minus the chance every pair misses — and it crosses 50% at 23. It is the number of pairs, not the number of people, that drives it.
- Does this apply to hashes and random IDs?
- Yes, and that is the more useful application. Set the possible values to the size of your output space and the draws to how many you expect to issue. It is the same formula that gives rise to the birthday bound in cryptography.
- Is the answer exact?
- Yes. Both the distinct-outcome count and the total are computed as exact integers and divided only at the end, so the result is accurate at both extremes rather than rounding to zero or one.
Related generators
- Permutation and Combination CalculatornPr and nCr side by side, exactly, with the difference between them worked through rather than assumed.
- Lottery Odds CalculatorExact odds for any lottery format — every prize tier, as a plain '1 in N' rather than a rounded percentage.
- Random Sample GeneratorDraw a sample without replacement from your own list, and see exactly how many different samples were possible.