A hash function turns content of any size (a word, a 4 GB file) into a fixed-length digest. MD5, SHA-1 and SHA-256 are the three you will meet most often. They are used the same way, but they offer very different levels of security: this guide explains what sets them apart and which one to use for your situation.
What a digest is (and what it is not)
A good hash function has three properties:
- Deterministic: the same input always gives the same digest, on any computer.
- Avalanche effect: changing a single character changes the whole result. The MD5 digest of “Hello” is
8b1a9953c4611296a827abf8c47804d7; that of “hello” is5d41402abc4b2a76b9719d911017c592. - One-way: you cannot recover the text from the digest. You can only hash a candidate text and compare.
So a hash is not encryption: there is no key and nothing to “decrypt”. Websites that claim to “decrypt MD5” actually look your digest up in huge tables of precomputed digests of common words. That is why a simple password hashed with MD5 can be recovered in seconds.
A cryptographic hash must also be collision resistant: it should be practically impossible to craft two different inputs with the same digest. That is exactly the property MD5, and later SHA-1, lost.
MD5 vs SHA-1 vs SHA-256 at a glance
| MD5 | SHA-1 | SHA-256 | |
|---|---|---|---|
| Published | 1992 (RFC 1321) | 1995 (FIPS 180-1) | 2001 (SHA-2 family) |
| Digest size | 128 bits, 32 hex characters | 160 bits, 40 characters | 256 bits, 64 characters |
| Collisions | Found in 2004, now computable in seconds | First public collision in 2017 (the “SHAttered” attack) | None known |
| Status | Broken for any security use | Deprecated; NIST plans to fully retire it by the end of 2030 | Recommended |
| Reasonable uses | Detecting accidental corruption, cache keys, de-duplication | Compatibility with older systems (Git commit IDs, for instance) | Download verification, signatures, certificates, integrity checks |
SHA-384 and SHA-512, also offered by the tool, belong to the same SHA-2 family as SHA-256: they produce longer digests (96 and 128 characters) and are only worth it when a protocol or a client requires them. For everyday use, SHA-256 is the right default.
Test values to check a tool
These digests are the ones published in the standards (the text “abc”) or produced by any compliant tool. If your program returns something else, the cause is the encoding or an invisible character.
| Text | Algorithm | Digest |
|---|---|---|
| abc | MD5 | 900150983cd24fb0d6963f7d28e17f72 |
| SHA-1 | a9993e364706816aba3e25717850c26c9cd0d89d | |
| SHA-256 | ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad | |
| (empty text) | MD5 | d41d8cd98f00b204e9800998ecf8427e |
| SHA-1 | da39a3ee5e6b4b0d3255bfef95601890afd80709 | |
| SHA-256 | e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 |
The trailing newline trap
On the command line, echo "Hello" | md5sum appends a newline to the text, so you get 09f7e02f1290be211da707a266f153b3 instead of 8b1a9953c4611296a827abf8c47804d7. Use printf 'Hello' or echo -n to hash exactly the text. Accented characters cause the same kind of mismatch: the digest depends on the bytes, hence on the encoding (UTF-8 on the web, and in our tool).
Verifying a downloaded file
Many software publishers list the SHA-256 digest of their files next to the download link. Compute the digest of the file you received and compare the two strings: if they match, the file was neither truncated nor altered in transit.
- Windows (PowerShell):
Get-FileHash .\file.iso(SHA-256 by default), orcertutil -hashfile file.iso SHA256 - macOS:
shasum -a 256 file.iso - Linux:
sha256sum file.iso
This check protects you from a corrupted download. It only protects you from a tampered file if the reference digest comes from a trusted source (the official site over HTTPS, a signature), not from the same page as a suspicious file.
What about passwords?
None of the three. MD5, SHA-1 and SHA-256 are designed to be fast, which is exactly what an attacker testing billions of passwords wants. To store passwords, use a slow, salted function built for the job: Argon2id (recommended by OWASP), scrypt or bcrypt. Your language or framework ships a proven implementation: do not write your own.
To create a strong password, the password generator and the password strength checker are better suited than a hash.
Frequently asked questions
Can an MD5 hash be “decoded”?
No. The original text can only be found if it appears in a table of precomputed digests (common words, leaked passwords) or if it is short enough to be guessed by brute force.
Can two different files have the same hash?
In theory yes, since the digest has a fixed size. With MD5 and SHA-1, researchers can deliberately craft such collisions. With SHA-256, none has ever been found.
Is the hash the same in upper and lower case?
The hexadecimal digest may be displayed in upper or lower case; it is the same value. The hashed text, however, is case-sensitive: “Hello” and “hello” give unrelated digests.
How is this different from Base64?
Base64 is a reversible encoding: it rewrites data in another alphabet, and you get the original back. A hash is irreversible and has a fixed length.