MD5 vs SHA-256: What's the Difference and When to Use Each

MD5 is fast but cryptographically broken; SHA-256 is the modern standard for integrity and signatures. Here's how cryptographic hashing actually works and which algorithm to reach for.

What a cryptographic hash actually does

A cryptographic hash function takes any input — a password, a file, a JSON payload — and produces a fixed-size string of bytes called a digest. The same input always yields the same digest, and even a one-byte change produces a completely different one.

Good hash functions share four properties:

  • One-way (preimage resistance): given a digest, you cannot feasibly recover the original input.
  • Fixed-size output: a 10-byte file and a 10-GB file both produce a digest of the same length (128 bits for MD5, 256 bits for SHA-256).
  • Deterministic: the same input always maps to the same digest, so hashes can be compared and stored as fingerprints.
  • Avalanche effect: flipping a single input bit changes roughly half the output bits, so similar inputs look unrelated.

Here is the avalanche effect with MD5 — note how a single capital letter rewrites the entire digest:

md5("The quick brown fox") = a2004f37730b9445670a738fa0fc9ee5
md5("the quick brown fox") = 4ed47e72a8d6c5042bb7f99b4b431d2c

MD5 and SHA-1 are broken — use them only as plain checksums

MD5 produces a 128-bit digest and is extremely fast, but it is cryptographically broken. Researchers can generate collisions — two different inputs that produce the same digest — in seconds on ordinary hardware. SHA-1 (160-bit) is broken too; the 2017 "SHAttered" attack produced two distinct PDFs with the same SHA-1 hash.

Because of this, MD5 and SHA-1 must never be used for anything security-related: digital signatures, certificates, integrity checks against a malicious adversary, or password storage. An attacker who can craft collisions can substitute a malicious file that hashes to the same value as a trusted one.

They are still acceptable for non-adversarial uses where you only care about accidental corruption, such as:

  • Deduplication — spotting identical files or rows by their hash.
  • Cache keys and ETags — fast, non-security identifiers.
  • Checksums for accidental corruption — verifying a download wasn't truncated (though SHA-256 is preferred even here).

SHA-256 is the current standard

SHA-256 is part of the SHA-2 family (which also includes SHA-384 and SHA-512). It produces a 256-bit digest and has no known practical collision or preimage attacks. It is the workhorse behind TLS certificates, code signing, Git object IDs (transitioning from SHA-1), blockchain proofs, and file-integrity manifests.

When you need a hash to resist a deliberate attacker — verifying that a download matches a publisher's posted checksum, signing data, or building a tamper-evident log — reach for SHA-256 (or SHA-512 for extra margin). A typical SHA-256 digest looks like:

sha256("hello") =
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Hashing is NOT encryption

This is the most common and most dangerous misconception. Encryption is reversible: it uses a key, and anyone with the key can decrypt the ciphertext back to plaintext. Hashing is one-way: there is no key and no "decrypt" operation — you cannot un-hash a digest back to its input.

If someone offers to "decrypt an MD5 hash," they are really running a lookup table or brute-forcing guesses until one matches. Treat a hash as a fingerprint, not as protected, recoverable data.

Why a fast hash is wrong for passwords

You should never store passwords with a plain MD5, SHA-1, or even SHA-256. The very thing that makes these hashes good for files — they are blazing fast — makes them terrible for passwords. An attacker who steals your database can compute billions of fast hashes per second on a GPU and crack common passwords quickly. Plain hashing also lets identical passwords share the same digest.

For passwords, use a slow, salted key derivation function (KDF) designed to resist brute force:

  • Argon2 — the modern winner of the Password Hashing Competition; memory-hard and tunable.
  • scrypt — also memory-hard, resisting GPU and ASIC attacks.
  • bcrypt — battle-tested and widely supported.

These functions add a unique salt per password (so identical passwords differ) and a deliberately high work factor (so each guess is expensive). General-purpose hashes like SHA-256 have none of that built in.

Quick reference: when to use which

  • Verify a download / file integrity vs. attackers: SHA-256.
  • Digital signatures, certificates, code signing: SHA-256 or SHA-512.
  • Dedup, cache keys, non-security fingerprints: MD5 is fine (fast and convenient).
  • Storing passwords: Argon2, scrypt, or bcrypt — never a bare hash.
  • Legacy systems forcing MD5/SHA-1 for security: migrate; they are not safe.

Try it in Formatly's Hash Generator

Formatly's Hash Generator computes MD5, SHA-1, SHA-256, SHA-384, and SHA-512 digests for any text you paste. It's a great way to see the avalanche effect, compare digest lengths, and confirm a file's checksum against a publisher's posted value. Everything runs 100% in your browser — your input is never uploaded to a server, so you can safely experiment with sensitive strings while you learn how each algorithm behaves.

FAQ

Is MD5 safe to use in 2026?

Only for non-security purposes. MD5 is cryptographically broken — practical collisions can be generated in seconds — so it must never be used for signatures, certificates, integrity checks against attackers, or passwords. It's still fine as a fast fingerprint for deduplication, cache keys, or detecting accidental corruption.

Can you decrypt an MD5 or SHA-256 hash?

No. Hashing is one-way and has no key, so there is nothing to decrypt. Tools that claim to "decrypt" a hash are really doing lookups or brute-forcing guesses until one produces a matching digest. Encryption is reversible with a key; hashing is not.

Should I use SHA-256 to store passwords?

No. SHA-256 is too fast, letting attackers test billions of guesses per second on a stolen database. Use a slow, salted key derivation function instead — Argon2, scrypt, or bcrypt — which add a unique salt and a tunable work factor to make brute-forcing expensive.

What's the difference between MD5 and SHA-256?

MD5 produces a 128-bit digest and is broken; SHA-256 produces a 256-bit digest and remains secure. Use SHA-256 (from the SHA-2 family) whenever security or tamper-resistance matters, and reserve MD5 for fast, non-adversarial fingerprinting like dedup or cache keys.

Is my data uploaded when I use Formatly's Hash Generator?

No. Formatly's Hash Generator runs entirely in your browser — the MD5, SHA-1, SHA-256, SHA-384, and SHA-512 digests are computed locally on your device and nothing is sent to a server. That means you can hash sensitive text without it ever leaving your machine.