Imagine you need to verify that a multi-gigabyte download arrived uncorrupted, or that your password is stored securely on a server, or that a document has not been tampered with. All three problems are solved by the same tool: a cryptographic hash function.
What a hash function is
A hash (also called a digest) is the result of applying a deterministic mathematical function to a set of data. The key is the word deterministic: the same input always produces exactly the same digest, no matter how many times you compute it. It is like a fingerprint: unique, reproducible and nearly impossible to forge.
The function takes input of arbitrary size — a single character, an entire book or a whole hard drive — and returns a fixed-length output. SHA-256, the algorithm you probably use daily without knowing it, always produces 256 bits: 64 hexadecimal characters, whether the input is one byte or one terabyte.
The four properties that make it secure
For a hash to serve in cryptography it must satisfy four properties, and violating any one of them brings down the whole algorithm:
- Determinism: same input, same output. Without this, everything else fails.
- Speed: it must compute in practical time even for huge inputs.
- Avalanche effect: changing a single input bit completely changes the output. Changing “password” to “passworf” produces two hashes with no apparent relation.
- Unidirectionality (preimage resistance): given the hash, reconstructing the input is computationally infeasible. It is not that it is hard to decipher: there simply is no inverse operation.
Why there is no “decrypting” a hash
Here lies the most common confusion: a hash is not encrypted, because there is nothing to decrypt. In encryption the operation has an inverse: with the key you recover the original text. In a hash, the information is mixed through compression and non-linear operations (bit rotations, modular additions, boolean functions such as XOR, AND and OR) that destroy the one-to-one relationship. Several inputs can even produce the same output: this is called a collision, and although infinitely many exist mathematically, finding one for SHA-256 would require on the order of 2^128 operations — an unapproachable number for any hardware.
SHA-256 inside its rounds
SHA-256 processes data in 512-bit blocks and applies 64 rounds of a structure called a compression function. Each round mixes the internal state (eight 32-bit registers, A through H) using bit-shift operations and majority and choice functions, adding a constant from a table of 64 values derived from the first digits of the cube roots of primes. After the 64 rounds, the resulting state is added to the block’s initial state, ensuring that each block depends on the previous one: that is where the avalanche effect is born.
Where you find it every day
Hashes are everywhere, almost always without you noticing:
- Password storage: the server stores the hash of your password, not the password. When you log in, it computes the hash of what you type and compares. Nobody, not even the database administrator, can see your real password.
- Download integrity: download pages show a SHA-256 checksum so you can verify the file was not corrupted or replaced.
- Version control: Git identifies every commit by its SHA-1 hash (the content of your code is, literally, its digest).
- Blockchain: each block chains the hash of the previous one, so modifying a single block invalidates the whole chain.
- Duplicate detection: cloud storage services deduplicate files by comparing hashes rather than content byte by byte.
Salt and the danger of dictionaries
Storing just the hash is not enough. An attacker with a dictionary attack — a list of millions of common passwords with their precomputed hashes, called a rainbow table — can reverse trivial hashes. The defense is salting: a random string added to the password before hashing, different for every user. With a salt, two users with the same password get different hashes, and precomputed tables stop working. That is why modern systems use deliberately slow and expensive functions such as bcrypt, scrypt or Argon2, designed to make each brute-force attempt costly in time and memory.
The algorithms that are no longer secure
Not all hashes are equal. MD5 and SHA-1 were standards for decades, but today they are broken: practical MD5 collisions were demonstrated in 2004, and in 2017 Google published a real SHA-1 collision. Finding two different inputs with the same digest allows creating malicious files that impersonate legitimate documents, which disqualifies them for digital signatures and integrity. That is why the industry moved to the SHA-2 family (SHA-256 and SHA-512) and to SHA-3, based on a completely different construction called Keccak, with a sponge structure instead of the classic Merkle-Damgård one.
A message inside a hash: HMAC
Hashes also serve to authenticate messages. HMAC (hash-based message authentication code) combines the message with a secret key in two passes over the hash: one with the key XORed with an inner constant (ipad) and another with the outer one (opad). The result is a code that only whoever knows the key can produce, and that also detects any modification of the content. It underpins signatures in payment APIs, JWT tokens and TLS protocols.
A tool that is not magic, but mathematics
Hashing does not make data disappear nor encrypt it: it reduces it to a compact, reproducible and unidirectional fingerprint. It is one of those pieces of cryptography so discreet that it goes unnoticed, and yet it upholds the integrity of your downloads, the security of your passwords, your Git history and even the blockchain. The next time you see a string of 64 hexadecimal characters at the foot of a file, you will know you are looking at the fingerprint of data that nobody should be able to forge.





