Contents
Three promises a hash keepsFour steps that mix up 'abc'How 'abc' becomes one 512-bit blockConstants taken from primes64 rounds: one turn that mixes eight wordsChange one letter, flip half the bitsWhy not for passwordsReason 1: it is too fastReason 2: the same password gives the same hashWhat to use: functions that are slow and memory-hungry on purposeCollision attacks have reached step 35 of 64Still strengths in what it was made forReferencesAs a developer you see 64-digit hex strings all the time. The digest after sha256: that scrolls past when you pull a container image, the SHA-256 checksum on a download page, the shasum -a 256 you type to check a file you just downloaded. They are all output from a hash function called SHA-256. Here is what you get for the three letters abc.
$ printf abc | shasum -a 256
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad -Whether the input is three letters or a multi-gigabyte file, the output is always 256 bits, 64 hex digits. And SHA-256 is still an excellent, unbroken hash as of November 2026. Even so, you should not store passwords with it. In short, two of SHA-256's strengths, being fast and always giving the same output for the same input, turn directly into weaknesses when the thing you are hashing is a password.
Three promises a hash keeps
SHA-256 is specified in FIPS 180-4 from the US National Institute of Standards and Technology (NIST). The document defines a secure hash like this: computationally infeasible 1) to find a message that corresponds to a given message digest, or 2) to find two different messages that produce the same message digest. This is usually split into three promises.
- Preimage resistance: given only a hash, you cannot find the input.
- Second-preimage resistance: given one input, you cannot find a different input with the same hash.
- Collision resistance: you cannot find any two inputs with the same hash.
'Cannot find' means the amount of computation is too large to be practical. The password story starts here. All three promises stop you from computing an input 'backward' from a hash. None of them stops an attacker from hashing candidate passwords one by one and comparing them to a stored value. That is computing the hash 'forward', and a hash function is built to do exactly that quickly.
Four steps that mix up 'abc'
How 'abc' becomes one 512-bit block
SHA-256 processes input in 512-bit (64-byte) blocks, so it first pads the input to fit. The rule in FIPS 180-4: append a single 1 bit to the message, add 0 bits until the length leaves a remainder of 448 when divided by 512, then write the original message length in the final 64 bits.
abc is 24 bits. Add one 1, 423 0s and a 64-bit length field, and you get 24 + 1 + 423 + 64 = 512 bits, exactly one block. The FIPS document uses this very example.
The rule creates an interesting boundary. The 64-bit length field has to sit at the end of the block, so the message plus the 1 bit must fit in 448 bits for one block to be enough. Up to 55 bytes (440 bits) you get one block. From 56 bytes (448 bits), adding the 1 already passes 448, so a whole extra block of zeros is added and the length goes at its end.
Most passwords are shorter than 55 bytes. So hashing one password with SHA-256 means running the compression function exactly once. For an attacker, checking one guess is just as cheap.
Constants taken from primes
SHA-256 has two sets of constants: eight initial values H(0) that the hash starts from, and 64 round constants K, one per round. At first glance they look arbitrary.
H(0) = 6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19
K = 428a2f98 71374491 b5c0fbcf e9b5dba5 ... c67178f2 (64 values)FIPS 180-4 says where they come from. H(0) is the first 32 bits of the fractional parts of the square roots of the first eight primes (2, 3, 5, …, 19). K is the same for the cube roots of the first 64 primes (2 through 311).
From the password side, it means there is no secret anywhere in the algorithm. The constants and the rules are public, so the attacker's SHA-256 computes exactly what the server's does. Whatever protects a password has to live outside the hash function: a salt, and a function made slow on purpose.
64 rounds: one turn that mixes eight words
The compression function carries a state of eight 32-bit words, a through h. For the first block that state is H(0). One round mixes the eight words once, and this repeats 64 times. The figure shows the actual values that change in the first round (t = 0) for abc.
As the figure shows, six words simply shift over. Two values are newly computed.
Every addition here is modulo 2^32. The four functions have unfamiliar names, but what they do is simple.
- Σ0, Σ1: rotate the word (ROTR) by three different distances and XOR the results. A change in one bit spreads to three places in the word.
- Ch(e, f, g): short for 'choose'. For each bit, take f's bit if e is 1 and g's bit if e is 0.
- Maj(a, b, c): short for 'majority'. For each bit, take whichever value most of a, b and c have.
- K_t: the cube-root constant from earlier. Adding a different value each round keeps the rounds from behaving identically.
- W_t: a word made from the message. The first 16 (W_0 to W_15) are the 512-bit block cut into 32-bit pieces, and the other 48 are made by rotating, shifting (σ0, σ1) and adding earlier W values.
After 64 rounds, the final state is added word by word to the starting state, and that is the result for this block. If there are more blocks, the result becomes the next block's starting state, and the eight words of the last block's result, joined together, are the hash. abc has a single block, so this is the ba7816bf… from the top of the post.
Look at the operations again: 32-bit addition plus bit operations like rotation and shifting, XOR, AND and NOT. These are the fastest kinds of operations a CPU has, and modern chips even ship dedicated instructions for the round computation. That is where the 'too fast' reason below comes from.
Change one letter, flip half the bits
After 64 rounds, a tiny difference in the input spreads across the whole output: the avalanche effect. Try changing one letter in either of the two inputs below. In the 256-bit grid, the disc flips over in every cell where the two hashes differ, and the comparator window shows the count as N / 256 (xx.x%).
A flip-disc panel showing the SHA-256 avalanche effect: each of its 256 discs is one output bit, and a disc flips over when that bit differs between the hashes of input A and input B. Change one character (abc to abd) and 122 of 256 bits (47.7%) flip. The grid follows the order of the output bits, not the positions of the input characters.
abc and abd differ only in the last letter, yet their hashes differ in 122 of 256 bits (47.7%). Two random 256-bit values differ in 128 bits on average, so the two hashes look like unrelated values.
abc → ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
abd → a52d159f262b2c6ddb724a61840befc36eb30c88877a4030b65cbe86298449c9So you cannot tell from the hashes that two passwords are similar, like password1 and password2. But that is all the avalanche effect does. The same input gives the same hash no matter how many times you feed it in. That property is the second reason in the next section.
Why not for passwords
Reason 1: it is too fast
A hash function is meant to check large files quickly, so faster is better. For this post, during research, we measured throughput by repeatedly hashing a 1 MB buffer with Python hashlib (OpenSSL 3.6.3) on an Apple M2 Mac. SHA-256 reached 2,265 MB per second, about 3.5 times faster than MD5 (634 MB).
SHA-256 beats the simpler MD5 because of hardware. The M2 has dedicated SHA-256 instructions (hw.optional.arm.FEAT_SHA256: 1). That is welcome news for checking file integrity, and equally welcome news for whoever is guessing passwords.
Passwords cannot keep up with that speed. The number of passwords people actually choose is nowhere near 2^256. When one hash is cheap, an attack that hashes a list of common passwords and their variations finishes in a practical amount of time.
Reason 2: the same password gives the same hash
SHA-256 has no secret, so the hash of password123 is the same on every server. If two users pick the same password, the same value lands in the database twice.
This lets the attacker do the work ahead of time. Hash common passwords once and keep them in a table (a rainbow table is a way of storing such a table in less space), and cracking a leaked list of hashes becomes a lookup. The computation happens once, and the same table works against every service that leaks.
The fix is to mix a random value that differs per user, a salt, into the password. As on the right of the figure, the same password now gives different hashes, so a precomputed table is useless and the attacker has to start over for each user. A salt alone leaves reason 1 untouched, so in practice you use the functions in the next section.
What to use: functions that are slow and memory-hungry on purpose
Password hashing functions are designed the opposite way from SHA-256. They build in a salt and deliberately spend time and memory on each computation. The server only computes it once per login, so a little slowness is bearable. OWASP's general rule is that one hash should take less than a second. An attacker who has to try billions of guesses pays that cost every single time.
The OWASP Password Storage Cheat Sheet recommends these, in this order, with these minimum settings (for scrypt, N is the CPU and memory cost, r the block size and p the parallelism).
| Function | OWASP minimum | Note |
|---|---|---|
| Argon2id | 19 MiB of memory, 2 iterations, parallelism 1 | First choice |
| scrypt | N = 2^17, r = 8, p = 1 | When Argon2id is not available |
| bcrypt | work factor 10 or more | Only in legacy systems where Argon2 and scrypt are not available. 72-byte input limit |
| PBKDF2 | 600,000 or more iterations of HMAC-SHA-256 | When FIPS compliance is required |
Below are Python examples, simplified for explanation. First, what not to do.
import hashlib
# Don't: done in one pass, and the same password always gives the same value
stored = hashlib.sha256(password.encode()).hexdigest()Here it is with Argon2id, using the argon2-cffi package and the OWASP minimums from the table.
# pip install argon2-cffi
from argon2 import PasswordHasher
from argon2.exceptions import VerifyMismatchError
ph = PasswordHasher(time_cost=2, memory_cost=19 * 1024, parallelism=1) # 19 MiB, 2 passes, parallelism 1
stored = ph.hash(password) # '$argon2id$v=19$m=19456,t=2,p=1$<salt>$<hash>' all in one string
try:
ph.verify(stored, attempt) # True if it matches
except VerifyMismatchError:
... # wrong passwordThe stored string carries the algorithm, the settings and the salt, so there is no separate salt to manage.
As the PBKDF2 row in the table above shows, SHA-256 does not disappear from password storage entirely. Wrapped in HMAC and repeated 600,000 times, it is fit for storing passwords. The problem is not SHA-256 itself but running it just once.
Collision attacks have reached step 35 of 64
Research into breaking SHA-256 starts with versions that have fewer rounds (papers call them steps). How many steps have produced an actual colliding pair is the gauge of how close attacks have come.
In December 2024, the ASIACRYPT talk The First Practical Collision for 31-Step SHA-256 presented an actual colliding pair, which per the slides took 1.2 hours on 64 threads.
In May 2026 the record moved again. Pushing the Limit of Memory-efficient Collision Attack Framework for SHA-2, accepted to CRYPTO 2026, reported the first practical collision attacks on 35-step SHA-256 and SHA-512. Practical collisions moved 4 steps further, and theoretical attacks reached 36 to 37 steps.
That is 4 more steps in two years. Still, there is no practical attack on all 64 steps, and counting steps alone, 29 remain.
Still strengths in what it was made for
Passwords call for care, but being fast and always giving the same output are plain strengths in what SHA-256 was made for. Identical content gets an identical name, so files and data can be referred to by their content.
References
Standards and official documents
- NIST, FIPS 180-4 Secure Hash Standard (2015.8.4 update)
- NIST, FIPS 180-4 full text PDF
- NIST, IR 8547 Transition to Post-Quantum Cryptography Standards (2026.10)
- NIST, NIST Transitioning Away from SHA-1 for All Applications (2022.12.15)
- Krawczyk, Bellare, Canetti, RFC 2104 HMAC (1997.2)
- Intel, Intel SHA Extensions white paper (2013.7)
Password storage
Attacks and incidents
- Thai Duong, Juliano Rizzo, Flickr's API Signature Forgery Vulnerability (2009.9.29)
- Li, Liu, Wang, New Records in Collision Attacks on SHA-2, EUROCRYPT 2024 (2024.2.27)
- Li, Liu, Wang, Dong, Sun, The First Practical Collision for 31-Step SHA-256, ASIACRYPT 2024 slides
- Li, Liu, Wang, Shi, Pushing the Limit of Memory-efficient Collision Attack Framework for SHA-2, CRYPTO 2026 (2026.5.28)
- Google Security Blog, Announcing the first SHA1 collision (2017.2.23)
- SHA-1 is a Shambles (2020.1)
Where it's used
- mempool.space (checked 2026.11.12)
- CA/B Forum, Ballot 118 (2014.10)
- Git, BreakingChanges
- Jonathan Corbet, Looking forward to Git 2.56 — and 3.0, LWN (2026.9.18)
- Karthik Nayak, What's new in Git 2.56.0, GitLab (2026.9.28)
- OCI Image Spec, Descriptor
- npm Docs, package-lock.json
- W3C, Subresource Integrity (2026.3.20 WD)
Quantum
- Babbush, Gidney, Boneh et al., Securing Elliptic Curve Cryptocurrencies against Quantum Vulnerabilities, Google Quantum AI (2026.3.30)
- BIP-360 P2MR (Draft)
- BIP-361 Post Quantum Migration and Legacy Signature Sunset (Draft)
GeekNews (Korean)
- SHA256 알고리듬 단계별 시각화 (2022.2.8)
- 미국 국립표준기술연구소(NIST), 2030년말까지 SHA-1 단계적 폐지 발표 (2022.12.16)
- JavaScript 해싱 속도 비교: MD5 vs SHA-256 (2025.1.15)
- Git의 다음 10년을 위한 진화 (2026.2.16)
- 양자 컴퓨팅 시점에 대한 암호공학 엔지니어의 관점 (2026.4.7)
Cover photo: Robert Stump on Unsplash.
