A fingerprint for data
A hash function takes any input (a word, a document, a 4 GB video) and turns it into a short, fixed-length string called a hash, digest or checksum. The same input always gives the same hash, and even a tiny change gives a completely different one:
| Input | SHA-256 hash |
hello | 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 |
Hello | 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969 |
hello! | ce06092fb948d9ffac7d1a376e404b26b7575bcc11ee05a4615fef4fec3a308b |
One capital letter or one exclamation mark changes every character of the result. Try it yourself in the Hash Generator.
What makes a good hash function
- Deterministic: the same input always produces the same hash, on any computer.
- One-way: you cannot work backwards from the hash to the input.
- Collision-resistant: it should be practically impossible to find two different inputs with the same hash.
- Fast to compute for checksums, which is useful, and also why fast hashes are wrong for passwords (more on that below).
Hashing is not encryption
Encryption is two-way: with the key, you get the original back. A hash has no key and cannot be reversed. It only lets you check whether something matches. Base64 is different again: it is just an encoding, and anyone can decode it.
The common algorithms
| Algorithm | Length | Status |
| MD5 | 128 bits (32 hex characters) | Broken since 2004; fine only for spotting accidental corruption |
| SHA-1 | 160 bits (40 hex characters) | Broken: the first real collision was published in 2017 |
| SHA-256 | 256 bits (64 hex characters) | Safe; the standard choice today |
| SHA-512 | 512 bits (128 hex characters) | Safe; often faster than SHA-256 on 64-bit computers |
Here is the word hello in each:
- MD5:
5d41402abc4b2a76b9719d911017c592 - SHA-1:
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d - SHA-256:
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
What "broken" means for MD5 and SHA-1
For MD5 and SHA-1, researchers can deliberately create two different files with the same hash. An attacker could use that to swap a harmless file for a malicious one with a matching checksum, or forge a signed document. Neither is broken in the sense of being reversible, and random corruption still changes the hash, so an MD5 checksum still catches a download that broke off halfway. It just cannot prove nobody tampered with the file.
SHA-256 and SHA-512 belong to the SHA-2 family, published in 2001, and no practical attack on them is known. SHA-3, standardised in 2015, is a different design kept as a backup.
Where hashes are used
- Checking downloads: developers publish the SHA-256 of their files; if yours matches, it is identical. See how to verify a checksum.
- Digital signatures and HTTPS certificates: the document or certificate is hashed, and the hash is signed.
- Git: every commit and file is identified by its hash. Git has long used SHA-1 and has added support for SHA-256.
- Bitcoin and other blockchains: blocks are chained together with SHA-256.
- Finding duplicate files: two files with the same SHA-256 are the same file.
Hashes and passwords
Websites should never store your password, only a hash of it; when you log in, they hash what you type and compare. But SHA-256 is the wrong tool here: it is so fast that an attacker with a leaked database can try billions of guesses per second. Passwords need slow, salted hashing designed for the job, such as bcrypt, scrypt or Argon2. A salt is a random value added to each password before hashing, so two people with the same password get different hashes.
Try it
The Hash Generator calculates MD5, SHA-1, SHA-256, SHA-384 and SHA-512 of any text or file at once, in your browser, and can compare them against a published checksum.