Explainer
How hash functions work: SHA-2, SHA-3 and collisions
A cryptographic hash function turns a message of any length into a short, fixed-length digest, and any change to the message should, with very high probability, produce a different digest.[1][2] NIST's approved hashes are the SHA-2 family (FIPS 180-4) and the SHA-3 family (FIPS 202), which rest on different designs so that one can back up the other.[3][4][5] The older SHA-1 has been undermined by collision attacks and is being phased out by the end of 2030.[6][7]
This page covers general-purpose cryptographic hash functions. Password storage uses deliberately slow, salted hashing schemes, covered in how websites store passwords. Choose a reading level in each section.
What a hash function does
A hash function takes any input, from a single word to a large file, and produces a short, fixed-length output called a digest or hash.[1] Think of it as a fingerprint for data. Change even one character of the input and the fingerprint should come out completely different. That is what lets a hash show whether data has been tampered with.[2]
Unlike encryption, hashing is one-way. There is no key that turns a digest back into the original message.[2][8]
NIST defines a hash algorithm as a mapping from a message of arbitrary length to a fixed-length message digest. Its approved algorithms are specified in FIPS 180-4 and FIPS 202.[1] FIPS 180-4 describes its algorithms as iterative, one-way functions. Any change to the input will, with very high probability, change the digest, which is the property digital signatures and MACs depend on.[2]
Three security properties
A good cryptographic hash has to meet three tests.[9]
- Collision resistance. Nobody should be able to find two different inputs that give the same hash.
- Preimage resistance. Given a hash, nobody should be able to find an input that produces it.
- Second preimage resistance. Given one input, nobody should be able to find a different input with the same hash.
NIST counts a hash’s collision strength as half its output length, so a 256-bit hash gives about 128 bits of collision resistance.[10]
NIST’s definitions:[9]
- Collision resistance: it is computationally infeasible to find two distinct inputs with the same hash value.
- Preimage resistance: given a randomly chosen hash value, it is infeasible to find an input that hashes to it.
- Second preimage resistance: it is infeasible to find a second input with the same hash as any specified input.
Collision strength in bits is half the output size, while preimage strength equals the output size.[10]
SHA-2 and SHA-3
The SHA-2 family, set out in NIST’s FIPS 180-4, includes SHA-256 and SHA-512. The number is the digest length in bits.[3]
SHA-3 came from an open competition. NIST opened it in 2007, when some feared SHA-2 might be at risk, and in 2012 picked an algorithm called Keccak from 64 entries.[11] At the time NIST said SHA-2 had held up well and remained secure; SHA-3 was meant as insurance in case SHA-2 is ever broken.[12] SHA-3 was published as FIPS 202 in 2015.[4]
FIPS 180-4 (August 2015) specifies SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256, with digests from 160 to 512 bits.[3] FIPS 202 specifies SHA3-224, SHA3-256, SHA3-384 and SHA3-512 plus the extendable-output functions SHAKE128 and SHAKE256. All are built on the KECCAK algorithm.[4] NIST approves only the four fixed-length SHA-3 functions as hash algorithms; the SHAKEs give variable-length output.[13] FIPS 202 presents SHA-3 as a supplement to SHA-2, not a replacement, giving resilience because the two rely on fundamentally different design principles.[5]
Why SHA-1 is being retired
SHA-1 dates from 1995. It is a slightly modified version of the first US government hash, SHA, from 1993.[14] Today’s computers can create fake messages with the same SHA-1 hash as a real one. These collision attacks have undermined it.[6]
NIST stopped allowing SHA-1 for digital signatures at the end of 2013. In 2022 it said SHA-1 should be phased out entirely by 31 December 2030.[6][7]
SHA-1 entered federal use in 1995 through FIPS 180-1.[14] NIST deprecated SHA-1 in 2011 and disallowed it for signatures at the end of 2013. NIST says collision attacks have since been used to undermine it.[6] It announced in December 2022 that SHA-1 should be phased out by 31 December 2030. IR 8547 (October 2026) confirms that SHA-1 is deprecated for all remaining applications and will be disallowed in FIPS-validated modules after 2030.[7]
Where hashes are used
Hashes are building blocks. Digital signatures usually sign a hash of a document rather than the whole document; see how digital signatures work.[15] Hashes combined with a secret key make message authentication codes (HMACs), which let two parties check that a message really came from someone holding the shared key.[16] Hashes also help generate random numbers and derive keys.[17]
FIPS 186-5 hashes the message before signing for RSA, ECDSA and HashEdDSA.[15] HMAC keys a hash function with a secret shared between sender and verifier. The verifier recomputes the tag over the received text and compares.[16] FIPS 202 lists signatures, key derivation and pseudorandom bit generation as core hash applications.[17]
Hashes and quantum computers
Quantum computers are a much smaller threat to hashes than to public-key systems such as RSA. NIST says it does not expect to need to replace its hash standards as part of the post-quantum switch.[18] Hashes are even the foundation of one of NIST’s new quantum-resistant signature standards, SLH-DSA.[19]
IR 8547 states that NIST’s symmetric standards, hash functions and XOFs included, are significantly less vulnerable to known quantum attacks than FIPS 186 and SP 800-56A/B. Approved symmetric primitives with at least 128 bits of classical security are believed to meet at least PQC security Category 1.[18] SLH-DSA (FIPS 205) rests on the presumed difficulty of finding hash preimages and related properties.[19]
Read next
Next in the crash course
How digital signatures work
How digital signatures prove who signed data and that it wasn't changed: key pairs, hashing, certificates, RSA, ECDSA and EdDSA, and e-signature law.
Questions readers ask
What is a hash function?
A hash function maps a message of any length to a fixed-length message digest. Cryptographic hash functions are one-way, and any change to the message should, with very high probability, give a different digest, which is why they are used to detect tampering.[1][2]
What is a hash collision?
A collision is two different inputs that produce the same hash. A collision-resistant hash makes finding one computationally infeasible. NIST rates a hash's collision resistance at half its output length in bits, so SHA-256 gives about 128 bits of collision resistance.[9][10]
What is the difference between SHA-2 and SHA-3?
SHA-2 is the family in FIPS 180-4, including SHA-256 and SHA-512. SHA-3, in FIPS 202, is based on the Keccak algorithm that won a NIST competition in 2012. NIST says the two rely on fundamentally different design principles, which gives resilience against future advances in attacks on hash functions.[3][4][11][5]
Is SHA-1 still safe to use?
No, according to NIST. Collision attacks have undermined SHA-1. NIST disallowed it for digital signatures at the end of 2013 and says it should be phased out completely by 31 December 2030 in favour of SHA-2 and SHA-3.[6][7]
Is hashing the same as encryption?
No. Encryption is designed to be reversed by someone with the key. A cryptographic hash is a one-way function that produces a fixed-length digest used to check whether data has changed.[2][8]
Do quantum computers break SHA-256?
NIST says its symmetric standards, including its hash functions, are much less vulnerable to known quantum attacks than public-key algorithms, and it does not expect to have to move away from them in the post-quantum transition. NIST's backup post-quantum signature standard, SLH-DSA, is built on hash functions.[18][19]
Sources
· 19 claims from 2 publishers
Each numbered claim is a statement we checked against the sources listed with it. Tap a number in the text to see its sources in place.
- [1]
NIST defines a hash algorithm as one that maps a message of arbitrary length to a fixed-length message digest; its approved hash algorithms are specified in FIPS 180-4 and FIPS 202. confirmedas of 2026-11-21
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Approved Algorithms (retrieved 2026-11-21)
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Approved Algorithms (retrieved 2026-11-21)
- [2]
FIPS 180-4 says its hash algorithms are iterative, one-way functions, and that any change to a message will, with very high probability, produce a different digest, which is what makes them useful for digital signatures and message authentication codes. confirmedas of 2015-08-04
- FIPS 180-4: Secure Hash Standard (SHS) · NIST · Primary source · 2015-08-04 · Section 1, Introduction (retrieved 2026-11-21)
- FIPS 180-4: Secure Hash Standard (SHS) · NIST · Primary source · 2015-08-04 · Section 1, Introduction (retrieved 2026-11-21)
- [3]
FIPS 180-4 (August 2015) specifies SHA-1 and the SHA-2 family (SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256), with digests from 160 to 512 bits depending on the algorithm. confirmedas of 2015-08-04
- FIPS 180-4: Secure Hash Standard (SHS) · NIST · Primary source · 2015-08-04 · Announcement, item 3, Explanation (retrieved 2026-11-21)
- FIPS 180-4: Secure Hash Standard (SHS) · NIST · Primary source · 2015-08-04 · Announcement, item 3 (retrieved 2026-11-21)
- [4]
FIPS 202 (August 2015) specifies the SHA-3 family, built on the KECCAK algorithm, with four fixed-length hash functions (SHA3-224, SHA3-256, SHA3-384 and SHA3-512) and two extendable-output functions (SHAKE128 and SHAKE256). confirmedas of 2015-08-04
- FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions · NIST · Primary source · 2015-08-04 · Abstract (retrieved 2026-11-21)
- FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions · NIST · Primary source · 2015-08-04 · Abstract (retrieved 2026-11-21)
- [5]
FIPS 202 says the SHA-3 hash functions supplement SHA-1 and SHA-2 rather than replace them, and that the two standards together give resilience against future advances in hash analysis because they rest on fundamentally different design principles. confirmedas of 2015-08-04
- FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions · NIST · Primary source · 2015-08-04 · Announcement, item 3 (retrieved 2026-11-21)
- [6]
NIST says collision attacks, in which powerful computers create fraudulent messages with the same hash as an original, have undermined SHA-1; it deprecated SHA-1 in 2011 and disallowed it for digital signatures at the end of 2013. confirmedas of 2026-11-21
- NIST Retires SHA-1 Cryptographic Algorithm · NIST · Primary source · 2022-12-15 · Paragraph 6 (retrieved 2026-11-21)
- NIST Retires SHA-1 Cryptographic Algorithm · NIST · Primary source · 2022-12-15 · Paragraph 6 (retrieved 2026-11-21)
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Approved Algorithms, SHA-1 (retrieved 2026-11-21)
- [7]
In December 2022 NIST announced that SHA-1 should be phased out by 31 December 2030 in favour of SHA-2 and SHA-3; its October 2026 IR 8547 says SHA-1 is deprecated for all remaining uses and will be disallowed in FIPS-validated cryptographic modules after 2030. confirmedas of 2026-10-27
- NIST Retires SHA-1 Cryptographic Algorithm · NIST · Primary source · 2022-12-15 · Paragraph 2 (retrieved 2026-11-21)
- NIST IR 8547: Transition to Post-Quantum Cryptography Standards · NIST · Primary source · 2026-10-27 · Table 8, footnote 4 (retrieved 2026-11-21)
- [8]
NIST's Secure Hash Standard specifies hash algorithms that produce message digests, which are used to detect whether a message has been changed since the digest was generated. confirmedas of 2015-08-04
- FIPS 180-4: Secure Hash Standard (SHS) · NIST Computer Security Resource Center · Primary source · 2015-08-04 · Abstract (retrieved 2026-11-07)
- [9]
NIST lists three security properties for hash functions - collision resistance (it is infeasible to find two different inputs with the same hash), preimage resistance (infeasible to find an input that produces a given hash) and second preimage resistance (infeasible to find a second input with the same hash as a given input). confirmedas of 2026-11-21
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Security Strengths (retrieved 2026-11-21)
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Security Strengths (retrieved 2026-11-21)
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Security Strengths (retrieved 2026-11-21)
- [10]
According to NIST, a hash function's collision resistance in bits is half its output size, while its preimage resistance equals its output size. confirmedas of 2026-11-21
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Security Strengths (retrieved 2026-11-21)
- [11]
In October 2012 NIST named Keccak the winner of its five-year SHA-3 competition; it beat 63 other submissions received after an open call in 2007, issued when it was thought SHA-2 might be threatened. confirmedas of 2012-10-02
- NIST Selects Winner of Secure Hash Algorithm (SHA-3) Competition · NIST · Primary source · 2012-10-02 · Paragraph 1 (retrieved 2026-11-21)
- NIST Selects Winner of Secure Hash Algorithm (SHA-3) Competition · NIST · Primary source · 2012-10-02 · Paragraph 2 (retrieved 2026-11-21)
- [12]
When it announced SHA-3 in 2012, NIST said SHA-2 had held up well and that it considered SHA-2 secure and suitable for general use, with SHA-3 serving as insurance in case SHA-2 was ever broken. confirmedas of 2012-10-02
- NIST Selects Winner of Secure Hash Algorithm (SHA-3) Competition · NIST · Primary source · 2012-10-02 · Paragraph 6 (retrieved 2026-11-21)
- NIST Selects Winner of Secure Hash Algorithm (SHA-3) Competition · NIST · Primary source · 2012-10-02 · Paragraph 7 (retrieved 2026-11-21)
- [13]
NIST says only the four fixed-length SHA-3 algorithms are approved hash algorithms; the SHAKE functions support variable-length outputs and can be specialised into hash functions subject to additional security considerations. confirmedas of 2026-11-21
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · Approved Algorithms (retrieved 2026-11-21)
- Hash Functions (project page) · NIST Computer Security Resource Center · Primary source · SHA-3 Derived Functions (retrieved 2026-11-21)
- [14]
SHA-1 has been in use since 1995 as part of FIPS 180-1; it is a slightly modified version of SHA, the first hash function the US government standardised for widespread use, in 1993. confirmedas of 2022-12-15
- NIST Retires SHA-1 Cryptographic Algorithm · NIST · Primary source · 2022-12-15 · Paragraph 2 (retrieved 2026-11-21)
- NIST Retires SHA-1 Cryptographic Algorithm · NIST · Primary source · 2022-12-15 · Paragraph 2 (retrieved 2026-11-21)
- [15]
For RSA, ECDSA and HashEdDSA signatures, FIPS 186-5 has the message first converted into a fixed-length digest by an approved hash function; plain EdDSA signs the message without hashing it first. confirmedas of 2023-02-03
- FIPS 186-5: Digital Signature Standard (DSS) · NIST · Primary source · 2023-02-03 · Section 3 (retrieved 2026-11-21)
- FIPS 186-5: Digital Signature Standard (DSS) · NIST · Primary source · 2023-02-03 · Section 3, footnote 5 (retrieved 2026-11-21)
- [16]
HMAC is a message authentication code built from a hash function and a secret key shared between the sender and the verifier; the verifier recomputes the HMAC over the received message and checks that it matches. confirmedas of 2012-08-24
- NIST SP 800-107 Rev. 1: Recommendation for Applications Using Approved Hash Algorithms · NIST · Primary source · 2012-08-24 · Section 5.3, HMAC (retrieved 2026-11-21)
- NIST SP 800-107 Rev. 1: Recommendation for Applications Using Approved Hash Algorithms · NIST · Primary source · 2012-08-24 · Section 5.3 (retrieved 2026-11-21)
- NIST SP 800-107 Rev. 1: Recommendation for Applications Using Approved Hash Algorithms · NIST · Primary source · 2012-08-24 · Section 5.3 (retrieved 2026-11-21)
- [17]
FIPS 202 names the generation and verification of digital signatures, key derivation and pseudorandom bit generation as important applications of hash functions. confirmedas of 2015-08-04
- FIPS 202: SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions · NIST · Primary source · 2015-08-04 · Abstract (retrieved 2026-11-21)
- [18]
NIST's final IR 8547 says its symmetric standards, including hash functions and block ciphers such as AES, are significantly less vulnerable to known quantum attacks than its public-key standards, that approved symmetric primitives with at least 128 bits of classical security are believed to meet at least its lowest post-quantum security category, and that it does not expect to need to move away from them in the post-quantum migration. confirmedas of 2026-10-27
- NIST IR 8547: Transition to Post-Quantum Cryptography Standards · NIST · Primary source · 2026-10-27 · Section 4.1.3, Symmetric Cryptography (retrieved 2026-11-21)
- NIST IR 8547: Transition to Post-Quantum Cryptography Standards · NIST · Primary source · 2026-10-27 · Section 4.1.3 (retrieved 2026-11-21)
- NIST IR 8547: Transition to Post-Quantum Cryptography Standards · NIST · Primary source · 2026-10-27 · Section 2.1.3, Symmetric Cryptography (retrieved 2026-11-21)
- [19]
FIPS 205 says SLH-DSA's security relies on the presumed difficulty of finding preimages for hash functions and related properties of those hash functions. confirmedas of 2024-08-13
- FIPS 205: Stateless Hash-Based Digital Signature Standard · NIST · Primary source · 2024-08-13 (retrieved 2026-10-10)
Revision history (1)
- Page created.
Created Nov 21, 2026. Last reviewed by an editor on Nov 22, 2026. Next scheduled review: Aug 2, 2027.
Cite this page
"How hash functions work: SHA-2, SHA-3 and collisions." ContentLora, updated Nov 21, 2026. https://contentlora.com/explain/how-hash-functions-work
Spotted an error? Suggest a correction or emailcorrections@contentlora.com.