The guide
A PIN is a tiny secret kept safe by a counter, unless a person chose the digits
Ten thousand four-digit codes sound like plenty until people pick them, which is why the arithmetic of rules, lockouts and length matters more than any single digit.
- 13.29 bits entropy of a four-digit PIN drawn at random
- 3.7% share of 1234 among four-digit strings in leaked RockYou passwords
- 11 to 18 wallets stolen per bank card opened by guessing birthdays, in one study
- 3,404 four-digit codes left when all seven exclusion rules are on
- 0.088% chance of guessing one of those 3,404 codes in three tries
Read the full guide Fold the guide
A PIN is the weakest secret most people own on purpose. Four digits make ten thousand possible codes, and a thief with unlimited tries would be through all of them before lunch.
Yet PINs guard bank cards, phones and front doors, and for the most part they hold. Two things make that possible. One is a counter that stops the guessing after a few failures. The other is an assumption that every code is as likely as every other. The first is engineering. The second is false whenever a person picks the digits.
The history is short. PINs arrived with British cash machines in 1967, six digits long on one system and four on another, and the engineer John Shepherd-Barron said the length came down to four after his wife could not remember six random digits. Banks assigned the codes at first. Letting customers choose began in the 1980s, as a marketing tactic. The EMV card standard requires support for PINs of 4 to 12 digits, and the banking standard ISO 9564-1 allows the same span while advising issuers not to assign more than six.
What people actually choose
Nobody has published a large set of real bank PINs. In 2012 three researchers at Cambridge, Joseph Bonneau, Sören Preibusch and Ross Anderson, used two stand-ins: 1,778,095 four-digit strings found inside leaked RockYou passwords, and 204,508 unlock codes collected by an iPhone app. In the first set, 1234 turned up 66,193 times, which is 3.7% of everything, while the rarest code, 8439, appeared 10 times. In the second, 1234 led again with 4.3%, and 46 of the ten thousand codes were never seen at all.
The patterns were not subtle. Plotted on a grid, the passwords showed a bright stripe of recent years and a block of calendar dates in month-day and day-month order. The study’s list of habits reads like a catalogue of shortcuts: dates written as DDMM, MMDD, MMYY or a plain year; keys in a row or at the four corners of the pad; a vertical swipe such as 8520; repeated pairs such as 2525; runs such as 4567 and 3210. Then there are words. On a telephone keypad the letters L, O, V and E sit on 5, 6, 8 and 3, and 5683 stood out sharply.
Banking turned out better than those leaks suggest, because many people never choose. The researchers surveyed 1,337 people in the United States, 1,108 of whom had a four-digit card PIN, and 805 described how they got it. Almost 64% used random or near-random digits, and most of those had simply kept the code the bank issued. About 23% used a date, about 9% a pattern on the keypad and 5% a numeric pattern. Among the date users, 29% had picked their own birthday. And 99% of respondents who were asked carried something showing their date of birth next to the card.
Put together, those numbers price a stolen wallet. For bank PINs as a whole the study estimated that three guesses succeed 1.4% of the time and six guesses 1.9%, against 0.03% and 0.06% for random four-digit codes. A thief who reads the birthday off a driving licence does far better: 8.2% with six guesses. The authors’ conclusion gave the paper its title: guessing birthdays opens one card for every 11 to 18 wallets stolen.
More digits do not rescue a chosen PIN. A 2020 study of 1,220 people asked to pick phone unlock codes found that, against an attacker limited to 10, 30 or 100 guesses, six-digit PINs gave little to no increase in security over four-digit ones.
Random, and what the rules cost
A PIN drawn at random is a different kind of object. Claude Shannon measured uncertainty as the logarithm of the number of possibilities and showed that it is greatest when all of them are equally likely. A decimal digit is worth about three and a third bits, so four random digits carry 13.29 bits. More usefully, no guess is better than any other guess.
Getting there takes care. A computer produces random bytes, not digits, and the obvious conversion, the remainder after dividing by ten, favors the low digits because 256 is not a multiple of ten. The OpenBSD manual calls that fault modulo bias. The cure in NIST’s guidance is to discard: take four random bits, giving 0 to 15, throw away anything from 10 up, and draw again. The standard says the result has no skew. A browser gets its bytes from crypto.getRandomValues, which Mozilla documents as a source of cryptographically strong random values.
Then comes an awkward fact. A fair draw will sometimes produce 1234. It happens once in ten thousand draws, and when it does the owner holds the first code any thief tries. Hence exclusion rules: draw again whenever the result looks like something a person would have chosen.
The tool on this page counts exactly what each rule costs. Set it to 4 digits. Alone, the rule against a doubled digit removes 2,710 of the 10,000 codes; requiring every digit to differ removes 4,960; the date rule removes 2,432; three-digit runs go with 380 codes, straight keypad lines with 358, palindromes with 100 and repeated blocks with 100. The rules overlap heavily, so switching on all seven leaves 3,404 codes. The entropy readout falls from 13.29 bits to 11.73.
That is a real loss, and it should be stated plainly. Against someone who knows precisely which rules were used, the chance of a hit in three tries rises from 3 in 10,000, which is 0.03%, to 3 in 3,404, which is 0.088%. So why exclude anything? Because real guessers do not know your rules. They know people. The Cambridge paper ends with a suggested blacklist of 100 PINs, sixty of them the years 1956 to 2015. The seven rules remove 98 of the 100. The two survivors are words: 5683, which is love again, and 7465, whose keys carry P, I, N and K.
The trade is cheap. The same paper found that banning its hundred codes cut the six-guess success rate from 1.9% to 0.2%. The phone study found tiny blocklists nearly useless, including the list of 274 four-digit codes built into iOS, and put the best balance near a tenth of all codes, because people grow frustrated when a choice is rejected. A generator has no feelings about a redraw. It can throw away two thirds of the codes and nobody is inconvenienced.
One rule is blunter than it looks. Any code beginning 01 through 12 reads as a month followed by a year, so with the date rule on, no four-digit PIN starts that way. The rule does know its calendar, though: 29 February counts only where the year allows it, and 1900, a century year not divisible by 400, was not a leap year.
The counter does the work
Thirteen bits is nothing. What makes it enough is that the lock stops listening. Blocking a payment card after three wrong guesses is standard practice, and because cash withdrawals and payments are counted separately, a thief with a card reader can typically make six. That is where the often-quoted 0.03% comes from, with the caveat, as one encyclopedia entry puts it, that the figure holds only if all PINs are equally likely.
Rule-makers treat the counter as part of the PIN. NIST lets an authenticator be unlocked with a secret as short as four characters, says six is better, and allows it to be entirely numeric. The condition is strict: no more than 10 consecutive failed attempts, after which the authenticator must be disabled. An iPhone works in the same spirit. The 2020 phone study set out its limits: the first six guesses fit inside a minute, eight take 21 minutes, and ten take 1 hour 36 minutes, after which the phone disables itself and has to be reset, or wipes its data if the owner has switched that option on.
Length and tries multiply. Microsoft’s description of the security chip in a Windows PC gives an example: a chip that allows 32 guesses at once and then one more every two hours yields about 4,415 guesses a year, enough to walk through every four-digit PIN in a little over two years. Windows later raised the minimum drive-unlock PIN to six characters. Each added digit cuts the odds of a blind guess tenfold. Halving the allowed tries only halves them.
So the number worth knowing is a ratio: tries allowed over codes left. With the tool’s six default rules a six-digit PIN has 459,761 possible values, and ten tries against it succeed 0.0022% of the time.
Where a PIN is the wrong tool
Take the counter away and the arithmetic collapses. A phone keeps its encryption key in tamper-resistant hardware and entangles it with the unlock code, so every guess has to be made on the device itself, where the counter lives. A 2021 study of attacks on iPhone passcodes reports that a single check is designed to take about 80 milliseconds. Suppose that were the only defense. Ten thousand codes at 80 milliseconds each take 800 seconds, about thirteen minutes. A million six-digit codes take 80,000 seconds, roughly 22 hours. Those are the worst cases the study tabulates, and the 2020 phone study says as much: with so small a key space, every combination can be tested within minutes.
Anything an attacker can copy and test in private, such as an encrypted file or a password-protected document, has no counter at all. That is a job for a long password: NIST asks for at least 15 characters when a password stands alone.
A PIN earns its place only where the secret never leaves a device that counts. Microsoft makes the argument for Windows Hello in one sentence: the PIN does not compromise security because the system has built-in brute force protection and the PIN never leaves the device.
Randomness and rules cannot fix what happens around the keypad. In an experiment with 1,173 participants watching videos of someone unlocking a phone, a single viewing was enough to recover a six-digit PIN 10.8% of the time, and repeated viewings 26.5%. Habits matter as well: a third of the surveyed cardholders reused their bank PIN somewhere else, and over half had shared it. Nor can pattern rules see meaning. They do not know your house number, your phone number or the word your keys spell, which is what the tool’s banned-codes box is for.
The counts above also assume the attacker knows nothing except the rules. They say nothing about how a particular lock counts tries, or whether it counts them at all. Let a machine pick the digits, keep the rules, take six digits where six are allowed, and find out what happens after the third wrong guess. If the answer is nothing, use a password.
Sources
Every source consulted for this guide. Links checked October 6, 2026.
- A birthday present every eleven wallets? The security of customer-chosen banking PINs Joseph Bonneau, Sören Preibusch and Ross Anderson, Financial Cryptography 2012 (copy on the first author's site)
- This PIN Can Be Easily Guessed: Analyzing the Security of Smartphone Unlock PINs Markert, Bailey, Golla, Dürmuth and Aviv, IEEE Symposium on Security and Privacy 2020 (arXiv copy)
- Let's Take it Offline: Boosting Brute-Force Attacks on iPhone's User Authentication through SCA Lisovets, Knichel, Moos and Moradi, IACR Transactions on Cryptographic Hardware and Embedded Systems 2021, issue 3 (CC BY 4.0)
- Towards Baselines for Shoulder Surfing on Mobile Authentication Aviv, Davin, Wolf and Kuber, Annual Computer Security Applications Conference 2017 (arXiv copy)
- Authenticators National Institute of Standards and Technology, Special Publication 800-63B-4, Digital Identity Guidelines, section 3
- Trusted Platform Module (TPM) fundamentals Microsoft, windows-itpro-docs repository on GitHub (CC BY 4.0), archived by the Internet Archive
- Windows Hello for Business overview Microsoft, windows-itpro-docs repository on GitHub (CC BY 4.0), archived by the Internet Archive
- E.161: Arrangement of digits, letters and symbols on telephones and other devices that can be used for gaining access to a telephone network International Telecommunication Union, ITU-T Recommendation E.161 (02/2001)
- Personal identification number Wikipedia
- A Mathematical Theory of Communication C. E. Shannon, Bell System Technical Journal 27 (1948), reprint hosted by Harvard University
- Recommendation for Random Number Generation Using Deterministic Random Bit Generators National Institute of Standards and Technology, Special Publication 800-90A Revision 1 (Barker and Kelsey, 2015)
- Crypto: getRandomValues() method MDN Web Docs (Mozilla)
- arc4random(3) - OpenBSD manual pages OpenBSD
- Leap Years Astronomical Applications Department, U.S. Naval Observatory