In one sentence
A cryptographic hash function turns any input into a fixed-length digest such that the same input always gives the same output, a tiny change gives a completely different output, and — for a secure one — you cannot work back from the digest to the input or find two inputs that share it.
Why it matters
File integrity checks, malware IOC matching (a known-bad file's SHA-256), digital signatures, DKIM, SRI, Git commits, certificate fingerprints and TLS all lean on this one primitive. But "cryptographic hash" is not one uniform guarantee. MD5 (1992) and SHA-1 (1995) are both broken for security purposes — practical collision attacks exist for both (MD5 since 2004, SHA-1 since SHAttered in 2017, chosen-prefix since 2020) — while SHA-256 and the rest of SHA-2, and the SHA-3 family, remain sound. Seeing MD5 or SHA-1 used for anything security-relevant today — signatures, integrity of downloads, certificate fingerprints — is a finding, not a neutral implementation detail. (Using MD5 as a plain lookup key or a cache name where nobody can choose the input is fine; the property you need there is only speed.)
The three properties, and a common misreading
- Pre-image resistance — given a digest, you cannot find an input that produces it. This is what protects a leaked hash (of anything with enough entropy).
- Second pre-image resistance — given one input, you cannot find a different input with the same digest. This is what makes a published checksum meaningful.
- Collision resistance — you cannot find any two inputs with the same digest. This is the property MD5 and SHA-1 lost, and it is enough to forge signatures when the attacker controls both documents.
Digest sizes: MD5 128 bits (32 hex characters), SHA-1 160 (40), SHA-256 256 (64), SHA-512 512 (128), SHA3-256 also 64 hex. The length identifies the family but not the algorithm — SHA-256, SHA3-256 and BLAKE2s all produce 64 hex characters.
The misreading: "hashing" the general concept and "hashing passwords" are not interchangeable. A general-purpose hash such as SHA-256 is fast by design — ideal for checking a download against its published checksum, actively wrong for password storage, where fast is exactly what you do not want. Passwords need bcrypt, Argon2 or scrypt. And a hash alone does not authenticate: if the attacker can change the file, they can change the published checksum next to it; that needs a signature or an HMAC with a key.
Try it yourself hands-on
You have downloaded an installer and want to confirm it matches the publisher's SHA-256; separately, a log contains an unlabelled hash and you want to know what it is.
- Open the Hash Toolkit, load the file, and read the SHA-256. Compare it against the publisher's published value with the tool's verify mode (it checks character for character, which eyes do badly with 64 hex characters). Any difference means the file was altered or corrupted in transit. Hashing happens in your browser; the file is not uploaded.
- Where did the "published value" come from? If it was on the same download page over plain HTTP, it proves nothing. A value on an HTTPS page, in a signed release note, or in a
SHA256SUMSfile with a PGP signature is the real check. - For the unlabelled hash, use the Toolkit's identify mode: it narrows by length and alphabet — 32 hex is MD5 (or the same-length NTLM), 40 is SHA-1, 64 is SHA-256-sized, a
$-prefixed string is a password hash. Then verify against a known sample if you have one: hash a file you suspect it belongs to and see which algorithm matches. - Need integrity and authenticity for something you publish? The HMAC Generator shows what a keyed hash looks like — the construction webhooks and API signatures use; for a file, sign the checksum file with PGP.
Common misreadings
- Hashing is not encryption. There is no key and no way back; "we hash the data so it can be recovered later" is a design error.
- A hash of an IP address is still personal data. With four billion possible inputs, the pre-image is trivially brute-forced; hashing does not anonymise low-entropy values.
- Two files with the same MD5 are not necessarily the same file — and a malware author can make sure of it. Use SHA-256 for IOCs and expect feeds to carry both.