Security by ToolShack Team

Understanding Hash Functions: SHA-256, MD5, and Bcrypt

A clear explanation of what hash functions do, how SHA-256, MD5, and Bcrypt differ, and when to use each one in your applications.

Hash functions are one of the most fundamental building blocks in computer security. They underpin password storage, digital signatures, data integrity checks, and blockchain technology. Yet many developers use them without truly understanding how they differ — or worse, use the wrong one for the job. This guide explains what hash functions do and when to use SHA-256, MD5, and Bcrypt.

What a Hash Function Does

A hash function takes any input — a password, a file, a message, a string of any length — and produces a fixed-size string of characters called a hash. The output length is always the same regardless of input size: SHA-256 always produces 64 hex characters (256 bits), MD5 always produces 32 hex characters (128 bits), and so on.

The critical properties of a good hash function are:

  • Deterministic: The same input always produces the same output.
  • One-way: You cannot reverse the hash to recover the original input.
  • Collision-resistant: It is computationally infeasible to find two different inputs that produce the same hash.
  • Avalanche effect: A tiny change in input (flipping one bit) produces a completely different hash.

MD5: Fast but Broken

MD5 (Message Digest 5) was designed in 1991 by Ronald Rivest. It produces a 128-bit hash and was widely used for checksums, file verification, and even password storage.

Today, MD5 is cryptographically broken. Researchers demonstrated collision attacks — the ability to find two different inputs that produce the same MD5 hash — in 2004. Since then, practical collision attacks have become trivial. In 2008, researchers created a rogue CA certificate using an MD5 collision, proving that MD5 could no longer be trusted for security-critical applications.

However, MD5 is still useful for non-security purposes: file deduplication, cache keys, and data integrity checks where accidental corruption (not malicious tampering) is the concern.

Do not use MD5 for password storage, digital signatures, or any security-critical application. It is too fast and too broken.

SHA-256: The Industry 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 (64 hexadecimal characters) and is currently considered secure against all known practical attacks.

SHA-256 is used in:

  • Bitcoin and blockchain: Mining is the process of finding a SHA-256 hash that meets certain criteria.
  • Digital certificates (TLS/SSL): Your browser uses SHA-256 to verify the integrity of website certificates.
  • File integrity: Software publishers provide SHA-256 checksums so you can verify that a downloaded file has not been tampered with.
  • Data integrity: APIs and databases use SHA-256 to verify that data has not been corrupted during transmission.

You can generate SHA-256 hashes instantly with the ToolShack Hash Generator, which also supports MD5, SHA-1, and SHA-512.

Bcrypt: Built for Passwords

Bcrypt is not a general-purpose hash function — it is specifically designed for hashing passwords. It uses the Blowfish cipher and includes a configurable work factor that makes it deliberately slow.

Why would you want a hash function to be slow? Because passwords are typically short and predictable. A fast hash like SHA-256 lets an attacker try billions of password guesses per second on modern hardware. Bcrypt's work factor makes each guess take significantly longer. With a work factor of 12, each hash takes about 250ms to compute. That is fast enough for a login system but 100,000 times slower than SHA-256 for an attacker trying every possible password.

You can generate and verify Bcrypt hashes with the ToolShack Bcrypt Hash Generator, which lets you adjust the work factor and verify passwords against existing hashes.

Side-by-Side Comparison

Feature MD5 SHA-256 Bcrypt
Output size128 bits (32 hex)256 bits (64 hex)184 bits (60 chars)
SpeedVery fastFastSlow (by design)
Collision resistantNo (broken)YesYes
Good for passwordsNoNo (too fast)Yes (ideal)
Good for file integrityYes (non-security)YesNo (too slow)
Configurable work factorNoNoYes

Which One Should You Use?

  • Passwords: Use Bcrypt (or Argon2, which is newer and also excellent). Never use SHA-256 or MD5 for passwords.
  • Data integrity / checksums: Use SHA-256. It is secure, fast, and universally supported.
  • File deduplication / non-security hashing: MD5 is fine and fastest.
  • Digital signatures / certificates: Use SHA-256 or SHA-384.
  • Blockchain / proof-of-work: SHA-256 (Bitcoin) or the algorithm specified by the protocol.

Conclusion

Hash functions are simple in concept but nuanced in practice. MD5 is fast but broken for security. SHA-256 is the reliable all-rounder for integrity and verification. Bcrypt is purpose-built for passwords with a clever speed penalty that makes attacks impractical. Choosing the right one for your use case is one of the most important security decisions you can make. Use the ToolShack Hash Generator for quick SHA-256 and MD5 hashing, and the Bcrypt Generator for password hashing.

Tools Mentioned in This Article

Related Articles