·7 min read·Blog

MD5 vs SHA-256: Hash Functions Explained (And When Not to Use MD5)

Both MD5 and SHA-256 produce a fixed-length fingerprint of any input. One is cryptographically broken. Here's what hashing is, how they differ, and which to use.

What hash functions do

A cryptographic hash function takes any input (a string, a file, a password) and produces a fixed-length output called a hash or digest. Properties:

  • Deterministic: The same input always produces the same hash
  • One-way: You cannot reconstruct the original input from the hash
  • Avalanche effect: A tiny change in input produces a completely different hash
  • Fixed length: The output length is constant regardless of input length

MD5 produces a 128-bit (32 hex character) hash. SHA-256 produces a 256-bit (64 hex character) hash.

Generate both types of hashes with the free SHA-256 hash generator.

MD5: what it is and why it's broken for security

MD5 (Message Digest 5) was designed in 1991 as a cryptographic hash function. For decades it was used for password hashing, digital signatures, and file integrity checking.

The problem: MD5 is vulnerable to collision attacks. A collision means two different inputs produce the same MD5 hash. In 2004, researchers demonstrated the first practical MD5 collisions. By 2008, researchers had used MD5 collisions to forge a rogue SSL certificate — proving the attack was practical and dangerous.

A collision attack means: an attacker can create a malicious file that has the same MD5 hash as a legitimate file. If you're using MD5 to verify file integrity ("is this the file I expect?"), a collision attack defeats that check. An attacker can substitute the malicious file and your check passes.

MD5 has no known collision resistance — and hasn't for 20 years.

SHA-256: the current standard

SHA-256 (Secure Hash Algorithm 256-bit) is part of the SHA-2 family, designed by the NSA and published by NIST in 2001. It produces a 256-bit hash with no known practical collision attacks or pre-image attacks as of 2026.

SHA-256 is used in:

  • TLS certificates (HTTPS)
  • Bitcoin (mining and transaction hashing)
  • Code signing and software integrity verification
  • HMAC-SHA256 for API authentication signatures
  • Git (object addressing — though Git 2.42+ is migrating to SHA-256 as the new default)

When MD5 is still acceptable

Despite its cryptographic weakness, MD5 is still used and acceptable in specific non-security contexts:

  • Non-security checksums for accidental corruption. When you download a large file and want to verify it wasn't corrupted during transfer (not tampered with), MD5 is fine. Accidental corruption is detected; intentional tampering is not.
  • De-duplication. Hashing file contents to find duplicates in a local file system. No security implications — you just want to detect identical content.
  • Cache keys and database lookups. Using an MD5 hash of a string as a cache key or database identifier. The collision risk in this context is negligible and there are no security implications.
  • Legacy system compatibility. Some older APIs and protocols require MD5. Use it when required; document that it's not for security.

When to use SHA-256 instead

  • File integrity for security-sensitive downloads. Software signatures, firmware verification, OS images. Use SHA-256.
  • API request signing. HMAC-SHA256 is the standard for AWS, Stripe, GitHub webhooks, and most modern APIs.
  • Digital signatures and certificates. SHA-256 is the minimum. SHA-384 and SHA-512 are used for long-lived certificates.
  • Any cryptographic protocol. MD5 should not appear in any new security design.

Password hashing: use neither MD5 nor SHA-256

This is the most important point: do not use MD5 or SHA-256 to hash passwords. Both are fast hash functions — fast is exactly the wrong property for password hashing.

A modern GPU can compute 68 billion MD5 hashes per second. If an attacker obtains a database of MD5-hashed passwords, they can attempt all common passwords and dictionary words against every hash in seconds.

For passwords, use a deliberately slow key-derivation function:

  • bcrypt — standard, widely supported, proven in practice
  • Argon2id — NIST recommended, memory-hard (resists GPU/ASIC attacks), current best practice
  • scrypt — memory-hard, good for older systems that can't use Argon2

These algorithms are specifically designed to be slow and to require significant memory — making brute-force attacks computationally infeasible even after a database breach.

Comparing the outputs

AlgorithmOutput lengthHash of "hello"
MD532 hex chars (128 bits)5d41402abc4b2a76b9719d911017c592
SHA-140 hex chars (160 bits)aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
SHA-25664 hex chars (256 bits)2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Notice that changing a single character in the input ("hello" vs "Hello") produces completely different hashes — this is the avalanche effect in action.

Related tools


Written by Achraf A., founder of TheFreeAITools.

Browse by category

Not sure which tool you need? Start with a category.

Everything you can do — for free

No software to buy. No account to create. Just open a tool and get it done.

Work with images

Compress photos before sending them by email, resize pictures for social media, remove backgrounds, or pick the perfect color for a design project — all without installing any app.

Edit and format text

Count words and characters in an essay, compare two documents side by side, convert text to different formats, or generate placeholder text for a presentation.

Stay safe online

Create a strong unique password in one click, check how secure a password is, encode or decode data, and generate secure tokens — your data never leaves your device.

Calculate anything

BMI, loan repayments, unit conversions, date differences, and dozens of other everyday calculations — no spreadsheet or formula knowledge required.

The Free AI Tools is a free collection of 221+ online tools that work directly in your web browser — no download, no installation, no account required. Whether you need to compress an image for email, count words in an essay, generate a strong password, create a QR code for your business, or format JSON for development — you will find a simple, free tool here.

Every tool is privacy-first: your files, text, and data never leave your device. Tools cover image editing, text processing, developer utilities, security & encoding, SEO & web, design & CSS, and more.

☕ Support Us