Hash Functions Explained: MD5, SHA-1, SHA-256 & When to Use Each

May 7, 2026 • 8 min read • Try the free Hash Generator →

Hash functions are everywhere in software: verifying file integrity, storing passwords, generating cache keys, signing data, and powering blockchains. But not all hash functions are equal — some are cryptographically broken, some are fast by design, and some are intentionally slow. Choosing the wrong one for the wrong job can introduce serious security vulnerabilities.

What Is a Hash Function?

A hash function takes an input of any size and produces a fixed-size output called a hash, digest, or checksum. A good cryptographic hash function has four properties:

Example — the SHA-256 hash of "hello":

SHA256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Change even one character and the hash changes completely (the avalanche effect).

MD5

MD5 produces a 128-bit (32 hex character) hash. It was designed in 1991 and was once widely used for security purposes.

Status: Cryptographically broken

Collisions in MD5 can be generated in seconds on modern hardware — two different inputs can produce the same MD5 hash. This makes MD5 completely unsuitable for any security purpose.

Still acceptable for: Non-security checksums, content hashing for cache keys, deduplication of files in trusted environments where collision attacks are not a concern.

MD5("hello") = 5d41402abc4b2a76b9719d911017c592

SHA-1

SHA-1 produces a 160-bit (40 hex character) hash. It was the standard for many years and was used in SSL certificates and Git commits.

Status: Deprecated for security use

In 2017, Google's SHAttered attack demonstrated a practical SHA-1 collision. Major CAs stopped issuing SHA-1 certificates in 2017. Git still uses SHA-1 internally but is migrating to SHA-256.

Still acceptable for: Non-security checksums, legacy system compatibility. Do not use for new security-sensitive applications.

SHA1("hello") = aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

SHA-256

SHA-256 is part of the SHA-2 family and produces a 256-bit (64 hex character) hash. It is the current industry standard for most applications.

Status: Secure — recommended

No practical collisions have been found. It is used in TLS certificates, code signing, blockchain (Bitcoin), HMAC signing, and JWT tokens.

SHA256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

SHA-512

SHA-512 produces a 512-bit (128 hex character) hash. It offers a larger security margin than SHA-256 and can actually be faster on 64-bit processors.

Status: Secure — good for high-security applications

Use when: You need a larger hash for additional collision resistance, or when hashing large amounts of data on 64-bit systems where SHA-512 can outperform SHA-256.

Comparison Table

AlgorithmOutput SizeSecuritySpeedCommon Uses
MD5128-bit / 32 charsBrokenVery fastChecksums, cache keys
SHA-1160-bit / 40 charsDeprecatedFastLegacy systems, Git
SHA-256256-bit / 64 charsSecureFastTLS, code signing, JWT, blockchain
SHA-512512-bit / 128 charsVery secureFast on 64-bitHigh-security applications
bcrypt60 charsSecureIntentionally slowPassword hashing only
Argon2VariableBestIntentionally slowPassword hashing (recommended)

The Critical Rule: Don't Hash Passwords with SHA

Never use MD5, SHA-1, SHA-256, or SHA-512 to hash passwords. These algorithms are designed to be fast — modern GPUs can compute billions of SHA-256 hashes per second. An attacker with a leaked hash database can brute-force passwords in minutes.

For passwords, use a deliberately slow, memory-hard algorithm:

Practical Use Cases for SHA-256

Generate hashes instantly: Use NeatJSON's Hash Generator to compute MD5, SHA-1, SHA-256, and SHA-512 hashes for any text — all processed locally in your browser.

Frequently Asked Questions

Is MD5 safe to use?

MD5 is cryptographically broken and must not be used for security purposes. It is still acceptable for non-security use cases like generating content hashes for cache keys or deduplicating files in a trusted environment.

Should I use SHA-256 to hash passwords?

No. SHA-256 is too fast — GPUs can compute billions per second. Use bcrypt, scrypt, or Argon2id for passwords instead. These are intentionally slow and memory-intensive, making brute-force attacks impractical.

What is the difference between a hash and encryption?

Hashing is one-way: you cannot reverse a hash to get the original input (by design). Encryption is two-way: data encrypted with a key can be decrypted back to its original form. Use hashing for integrity verification and password storage; use encryption when you need to recover the original data.

Related Guides