Definition
What it is
A hash function takes input of any size — a password, a file, a container image, a commit — and produces output of fixed size. SHA-256 always returns 256 bits, whether the input is one byte or one terabyte. The output is called a digest, a hash value, or a fingerprint. The function is deterministic: the same input always produces the same output, byte for byte, across machines and years.
Two properties define it. First, it is one-way: given the digest, you cannot feasibly recover the input. Second, it is collision-resistant: finding two different inputs that produce the same digest is computationally infeasible for a modern algorithm. These two properties are what make hashes useful for integrity, storage, and identity — and what make them break the moment the underlying algorithm weakens.
Why it matters
A container image is pulled by digest. A Git commit is identified by hash. A password is stored as a hash. A TLS certificate signs a hash of the handshake. A package manager verifies the hash of every dependency it downloads. None of these trust the source; they trust the digest. If the digest matches, the content is the same. If it does not, the content has been altered, corrupted, or substituted.
The distinction between a fast hash (SHA-256) and a password hash (bcrypt, Argon2) is the difference between a checksum and a credential store. Fast hashes are designed to be cheap so they can be computed at line rate. Password hashes are designed to be expensive so brute force is slow. Using the wrong one is a common and consequential mistake.
How it works
The internal structure depends on the algorithm, but the external behaviour is uniform. Input is padded to a multiple of the block size, processed block by block through a compression function, and the final state is serialized as the digest. The avalanche effect means that flipping one bit of input flips roughly half the bits of the output, which is what makes the digest look random even for closely related inputs.
graph LR I[Input: any length] --> P[Padding] P --> B[Block 1..N] B --> C[Compression rounds] C --> D[Final state] D --> H[Digest: fixed length] H --> U[Integrity check / identity / index]
Git uses this property to build a Merkle tree of commits. Each commit hashes its tree and its parent hashes, so changing a file in a commit changes every hash above it. A container registry uses the digest as the immutable identifier: nginx@sha256:abc... always points to the same bytes, no matter what the latest tag points to that day. A package manager stores the expected digest next to each artifact and re-checks it at install time.
Choosing and using a hash in practice
Match the algorithm to the threat model
Use SHA-256 or SHA-3 for integrity and content addressing. Use bcrypt, scrypt or Argon2 for passwords. Never use MD5 or SHA-1 for anything new.
Verify at the boundary
Compute the digest when a payload crosses a trust boundary (download, upload, deploy) and compare it to the expected value from a signed source.
Pin the digest, not the tag
In container and package pipelines, deploy by digest, not by mutable tag. A tag can be rewritten; a digest cannot.
Plan for rotation
Every hash algorithm has a lifetime. Track deprecation timelines (MD5 broken, SHA-1 broken, SHA-256 in use, SHA-3 and BLAKE3 rising) and migrate before the pressure is external.
Common failures
A second failure is using a fast hash for passwords. SHA-256 was designed to be fast, and speed is exactly what an attacker wants. GPU rigs compute billions of SHA-256 hashes per second; they compute millions of bcrypt hashes per second at best. A leaked table of SHA-256 password hashes is cracked in hours; a leaked table of Argon2 hashes is not.
A third failure is verifying the digest after trusting the payload. If the downloader has already executed the installer before checking the hash, the check is theatre. Verification has to happen before use, and the expected digest has to come from a trusted, authenticated source — not from the same server that served the payload.
Origin
The word "hash" comes from the French hacher, to chop or mince, and entered English in the 17th century as a cooking term. The computing sense — turning arbitrary data into a fixed-size value — appeared in the 1950s with hash tables. Cryptographic hashing emerged in the 1970s with the work of Ralph Merkle and Martin Hellman on one-way functions. NIST standardised SHA-0 in 1993, SHA-1 in 1995, SHA-2 in 2001, and SHA-3 in 2015.
A hash function is a fundamental primitive of modern cryptography. Its security is measured not by whether it can be broken today, but by how long it will resist the attacks that have not yet been published.
— NIST, *FIPS 180-4: Secure Hash Standard*, 2015
Evidence
Timeline
1953 — IBM introduces the first hash table for symbol lookup in assemblers.
1979 — Merkle proposes hash trees (Merkle trees) for efficient verification of large data structures.
1993 — NIST publishes SHA-0; withdrawn two years later due to an undisclosed flaw.
1995 — SHA-1 published. Used everywhere for two decades.
2001 — SHA-2 (SHA-256, SHA-512) standardised by NIST.
2004 — MD5 collisions demonstrated by Wang et al.
2015 — SHA-3 (Keccak) standardised as FIPS 202.
2017 — SHAttered: practical SHA-1 collision.
2020s — BLAKE3 and post-quantum hash-based signatures gain adoption.
FAQ
- What is the difference between hashing and encryption?
Encryption is reversible with the right key; hashing is not reversible at all. If you need to recover the original data, use encryption. If you need to verify that data has not changed, use a hash. Storing passwords with reversible encryption is a common and serious mistake.
- Why not use MD5 if it is faster?
MD5 is broken for collision resistance. Two different inputs can be crafted to produce the same MD5 digest, which means an attacker can substitute one for the other without detection. Speed is irrelevant when the integrity guarantee no longer holds. Use SHA-256 or SHA-3.
- Can two different files have the same SHA-256 hash?
In theory yes, because the input space is larger than the output space. In practice no: finding a SHA-256 collision by brute force is infeasible with current and foreseeable computing. The security of the algorithm rests on that gap between theory and practice.
- Is a hash the same as a checksum?
A checksum is a broader term: it can be a simple arithmetic sum or a full cryptographic hash. A cryptographic hash is a checksum with strong security properties (one-way, collision-resistant). The word "checksum" does not imply cryptographic strength; the word "hash" in a security context usually does.
- How do I know which hash algorithm to use?
Follow the standards: SHA-256 or SHA-3 for integrity and content addressing, Argon2 or bcrypt for passwords, BLAKE3 where speed and modern design matter. Check NIST and IETF guidance periodically — algorithms are deprecated on a schedule, not on a surprise.
Connections
● broader ● narrower ● related
Used in the garden
- Changelog (1×)
Sources
NIST (2015). FIPS 180-4: Secure Hash Standard (SHS). https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
IETF (2011). RFC 6151: Updated Security Considerations for MD5 and HMAC-MD5. https://www.rfc-editor.org/rfc/rfc6151
Git (2024). Git Internals: Git Objects. https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
Docker (2024). Pull an image by digest. https://docs.docker.com/reference/cli/docker/image/pull/#pull-an-image-by-digest-immutable-identifier
NIST (2015). FIPS 202: SHA-3 Standard. https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf
Etymology
Origin: borrowed
hash(verb): from French hacher, to chop or mince; entered English in the 17th centuryfunction(noun): from Latin functio, performance or execution
Semantic network
● broader ● narrower ● related
Used in the garden
- Changelog (1×)
Sources
{"NIST (2015). FIPS 180-4":"Secure Hash Standard (SHS). https:\/\/nvlpubs.nist.gov\/nistpubs\/FIPS\/NIST.FIPS.180-4.pdf"}
IETF (2011). RFC 6151. https://www.rfc-editor.org/rfc/rfc6151
{"Git (2024). Git Internals":"Git Objects. https:\/\/git-scm.com\/book\/en\/v2\/Git-Internals-Git-Objects"}
Docker (2024). Pull an image by digest. https://docs.docker.com/reference/cli/docker/image/pull/#pull-an-image-by-digest-immutable-identifier
{"NIST (2015). FIPS 202":"SHA-3 Standard. https:\/\/nvlpubs.nist.gov\/nistpubs\/FIPS\/NIST.FIPS.202.pdf"}