Hash function
A function that maps data of any length to a short fixed-length value, used as a digital fingerprint in security and in Bitcoin.
📖 Dictionary: hash function · 📚 Library
A function that maps data of any length to a short fixed-length value, used as a digital fingerprint in security and in Bitcoin.
📖 Dictionary: hash function · 📚 Library
A hash function is a function that turns data of any length into a short, fixed-length value, designed so that the value works as a digital fingerprint of the data.[6]
NIST's glossary gives the core definition as a function on bit strings in which the length of the output is fixed.[6] The standards that NIST approves for security use take a message of nearly any size and produce a condensed representation called a message digest.[1] The output is also called a hash or hash value.
A cryptographic hash function is one that is built to resist attack, and NIST's glossary lists the properties expected of an approved one:[6]
A further property, second-preimage resistance, appears in NIST's definitions of approved hash functions alongside the other two.[6]
The use that gives hashing its place in security follows from these properties. The Secure Hash Standard states that any change to a message will, with very high probability, produce a different message digest, which lets a receiver determine whether the message's integrity has been preserved.[1] The same standard names digital signatures, message authentication codes and the generation of random numbers or bits as uses of that property.[1]
NIST specifies its approved hash algorithms in two standards.[3]
FIPS 180-4, the Secure Hash Standard (August 2015) covers SHA-1 and the SHA-2 family: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.[1][3] The standard describes each algorithm in two stages: preprocessing, which pads the message and splits it into fixed-size blocks, and hash computation, which works through those blocks to produce the digest.[1] The algorithms differ in digest size and in block and word size, as the standard's table shows:[1]
| Algorithm | Block size (bits) | Word size (bits) | Digest size (bits) |
|---|---|---|---|
| SHA-1 | 512 | 32 | 160 |
| SHA-224 | 512 | 32 | 224 |
| SHA-256 | 512 | 32 | 256 |
| SHA-384 | 1024 | 64 | 384 |
| SHA-512 | 1024 | 64 | 512 |
| SHA-512/224 | 1024 | 64 | 224 |
| SHA-512/256 | 1024 | 64 | 256 |
The standard says the algorithms differ most in the security strength they provide for the data being hashed.[1]
FIPS 202, the SHA-3 Standard was also released in August 2015. It specifies the SHA-3 family, based on the KECCAK algorithm that NIST selected in its SHA-3 Cryptographic Hash Algorithm Competition.[4] The family has four hash functions (SHA3-224, SHA3-256, SHA3-384 and SHA3-512) and two extendable-output functions, SHAKE128 and SHAKE256, and the standard supplements SHA-1 and SHA-2 rather than replacing them.[4] As of September 2026, NIST's page states that only the four fixed-length SHA-3 algorithms are approved as hash algorithms, and that the extendable-output functions can be used as hash functions subject to additional security considerations.[3]
Collision resistance can fail. NIST deprecated SHA-1 in 2011 and disallowed it for digital signatures at the end of 2013, and in December 2022 published a plan to transition away from its remaining limited use.[3]
On 23 February 2017, researchers at CWI Amsterdam and Google announced the first real SHA-1 collision, which they called SHAttered: two visibly different PDF files with the same SHA-1 value, while their SHA-256 values differ.[5] They put the cost at about nine quintillion SHA-1 computations, roughly 6,500 CPU-years and 110 GPU-years, and said it was thousands of times faster than brute force and expected to become cheaper over time.[5]
A later result removed the remaining practical doubt. In 2020 Gaëtan Leurent and Thomas Peyrin announced the first chosen-prefix collision for SHA-1, in which an attacker can choose two different starting texts and then find suffixes that make the two full messages collide.[7] They estimated the attack cost about 75,000 US dollars to run and put the cost of a classical SHA-1 collision at about 11,000 US dollars.[7] To show the effect they built two PGP keys with colliding SHA-1 certifications, and the issue was tracked as CVE-2019-14855 and addressed in GnuPG 2.2.18 by treating SHA-1 identity signatures created after 19 January 2019 as invalid.[7]

Via Wikimedia Commons: Hash Tree by Azaghal, CC0.
Bitcoin's design paper uses hashing in three places.
The paper also describes ownership as a chain of digital signatures, each made over a hash of the previous transaction and the next owner's public key.[2] See Bitcoin for the wider system.
A system that checks passwords should not keep them in readable form. The OWASP Password Storage Cheat Sheet says passwords should never be stored in plain text, and that because a hash is a one-way function, an attacker who obtains a hashed password cannot use it to log in as the victim.[8] It defines a salt as a unique, randomly generated string added to each password as part of the hashing process.[8]
The same guidance warns that fast hashing algorithms such as SHA-256 are not suitable for password storage, because algorithms such as MD5 and SHA-1 were designed to be fast.[8] It instead ranks purpose-built password hashes: Argon2id first, scrypt where Argon2id is unavailable, bcrypt for legacy systems, and PBKDF2 where FIPS-140 compliance is required.[8] Its stated minimums are, for Argon2id, 19 MiB of memory, an iteration count of 2 and one degree of parallelism, and, for PBKDF2 with HMAC-SHA-256, a work factor of 600,000 or more.[8] The page shows no date, so these figures should be checked against the current version of the cheat sheet.[8]