MD5, SHA-1, SHA-256, SHA-512 — What Are the Actual Differences?
Hash algorithm differences mostly come down to digest size, collision resistance, and whether the algorithm is still safe to use. MD5 and SHA-1 are legacy fingerprints; SHA-256 and SHA-512 are the ones you should reach for when security matters. If you want to compare outputs quickly, try our free all hashes tool.
What a hash actually is
A hash algorithm takes input of any length and turns it into a fixed-length output called a digest. The important part is that the same input always produces the same digest, but even a tiny input change should produce a completely different result. That makes hashes useful for file integrity checks, content fingerprints, deduping data, and password storage.
Hashes are not encryption. Encryption is meant to be reversed with the right key; hashing is meant to be one-way. If someone gets a hash, they should not be able to recover the original text from it in any practical sense.
A quick mental model: if encryption is a locked box, hashing is a shredder with a label on the confetti. The label is the digest. The confetti is all you get back.
The real differences between MD5, SHA-1, SHA-256, and SHA-512
The first obvious difference is output length. MD5 produces 128-bit digests, SHA-1 produces 160-bit digests, SHA-256 produces 256-bit digests, and SHA-512 produces 512-bit digests. More bits usually mean a larger search space, which makes brute-force work harder and collision attacks more expensive.
But digest length is only part of the story. The internal design matters too, because some algorithms were broken by advances in cryptanalysis long before brute force became realistic. That is why MD5 and SHA-1 are considered unsafe for security-sensitive uses even though they still produce valid hashes.
- MD5: fast, short, and broken for collision resistance.
- SHA-1: slightly larger, also broken for collision resistance.
- SHA-256: modern, widely supported, good default for security.
- SHA-512: larger digest, strong security, often useful on 64-bit systems.
If you want the blunt version: MD5 and SHA-1 are fine for non-adversarial checksums, but not for anything where an attacker gets a vote. SHA-256 and SHA-512 are the practical security choices today.
Speed is not the same as safety
People often ask which hash is “best” because it is faster. That is the wrong first question for security work. A fast hash is great for integrity checks and terrible for password storage, because attackers also like fast hashes.
MD5 is fast. SHA-1 is fast. SHA-256 and SHA-512 are also quite fast in modern runtimes and hardware, but they are designed with stronger security margins. For password storage, you should not use any of these alone; use a dedicated password hash like bcrypt, scrypt, or Argon2 instead.
For file verification, speed can matter. A release pipeline hashing large artifacts, for example, may prefer SHA-256 because it is broadly trusted and widely available, while a checksum on a temporary cache file may not need anything more exotic than a quick CRC. Different jobs, different tools.
If you are comparing hashes in a browser and the inputs look suspiciously different, it can help to check the raw text first. Our guide to diff tools covers why a tiny whitespace change can send you chasing the wrong bug.
Collision resistance is the part that actually breaks trust
A collision happens when two different inputs produce the same hash. In theory, all hash functions can collide eventually because the output space is fixed. In practice, what matters is whether collisions are easy enough to find that the hash stops being trustworthy.
MD5 and SHA-1 are collision-broken. That means attackers can deliberately craft different inputs with the same digest, which kills their use in signatures, certificate checks, and any workflow where the hash is supposed to prove authenticity. This is not academic. It is why “looks random” is not the same as “cryptographically safe.”
SHA-256 and SHA-512 are still considered collision-resistant for normal use. That does not mean forever. It means that with current public knowledge and realistic resources, they are still the sane choice for new systems.
Rule of thumb: if an attacker can choose the input, avoid MD5 and SHA-1. If you only need a quick checksum for accidental corruption, legacy hashes may still be tolerated in narrow, non-security contexts.
When to use each one
Use the weakest hash that still meets the job, but do not confuse “weakest” with “obsolete.” A checksum for a downloaded file is not the same thing as a password hash or a digital signature. The threat model decides the answer.
- MD5: only for legacy compatibility or non-adversarial checks where collision attacks do not matter.
- SHA-1: mostly legacy compatibility; avoid for new security-sensitive work.
- SHA-256: the default choice for modern integrity checks, signing workflows, and general security use.
- SHA-512: good when you want a larger digest or are already working in a SHA-2-based system.
One subtle point: SHA-512 is not simply “SHA-256 but longer.” It uses a different internal configuration and is often efficient on 64-bit CPUs. In some environments it can be as fast as or faster than SHA-256, even with the larger output.
If you are building an API, storing file fingerprints, or validating downloads, SHA-256 is usually the boring correct answer. Boring is good when the alternative is a postmortem.
How these hashes behave in code
Most modern languages expose all of these through a standard crypto or hash library. The workflow is usually the same: feed bytes in, get a hex digest out. Here is a tiny Node.js example using SHA-256:
import { createHash } from 'crypto';
const input = 'Chunky Munster';
const digest = createHash('sha256').update(input, 'utf8').digest('hex');
console.log(digest);The same pattern works for MD5 or SHA-1 in many runtimes, but availability is not the same as safety. A language letting you call md5 does not mean you should use it for security. It just means the function exists because old systems still need to be read.
One practical detail: always hash bytes, not abstract “text.” Encoding matters. If one system hashes UTF-8 and another hashes UTF-16 or a normalized version of the same string, the digest will differ even though the visible text looks identical.
A Worked Example
Say you want to verify that a downloaded config file has not changed. The file originally shipped with a published SHA-256 hash, and you want to check the local copy before deploying it. The idea is simple: hash the file, compare the digest, and only continue if they match.
Here is the kind of input and output you might see:
Original file content:
api_url=https://api.example.test
mode=production
retry_limit=3
SHA-256 digest:
3c6c13d6c2b0d8c3d0cb8ec4af2c7f7b1e8f4d2a3f0aa9f8d0b2e6d9d2c3a1b0
Changed file content:
api_url=https://api.example.test
mode=production
retry_limit=4
SHA-256 digest:
8b9f3c2c6b1d4ef4d0f8f7c1a2e5b3c9d1e0f7a8b2c4d6e9f1a0b3c5d7e8f901That single-line change produces a completely different digest. This is normal. Hashes are intentionally sensitive, which is exactly why they are useful for integrity checks and why you should never expect “similar inputs” to produce “similar hashes.”
Now compare the same file pair in a text diff tool and you will immediately see the actual change: 3 became 4. That matters because when hash values differ, the hash is not telling you what changed. It is only telling you that something changed.
Frequently Asked Questions
Is MD5 still safe to use?
Not for security-sensitive work. MD5 is broken for collision resistance, which means attackers can deliberately create different inputs with the same hash. It is still sometimes used for legacy compatibility or basic non-adversarial checks, but that is a narrow lane.
Why is SHA-1 considered broken?
SHA-1 can also be attacked with practical collision techniques, so it is no longer trusted for signatures or authenticity checks. It may still appear in old systems, but new security designs should avoid it. SHA-256 is the safer default.
Is SHA-512 more secure than SHA-256?
Both are secure choices in modern use. SHA-512 has a larger digest and a different internal structure, which can be useful in some environments, but that does not automatically make it the better default. For most projects, SHA-256 is already strong enough and easier to standardize on.
Can I reverse a hash back to the original text?
Not directly. Hashes are one-way, so you cannot reliably reconstruct the input from the digest alone. You can sometimes guess common inputs by brute force or lookup tables, which is why weak passwords and unsalted hashes are a bad pairing.
Wrapping Up
The short version is still the right one: the main hash algorithm differences are output size, speed, and whether the algorithm is still trusted against collisions. MD5 and SHA-1 are legacy at this point. SHA-256 and SHA-512 are the sane modern options for integrity checks and security-adjacent work.
If you need to compare digests, verify sample outputs, or sanity-check how a string hashes under different algorithms, use the all hashes tool. Then move on with the boring, correct algorithm and save the debugging for the part that actually broke.