What is an MD5 and SHA-256 hash: complete guide to cryptographic hash functions

9 min read

Learn what MD5 and SHA-256 hashes are, how they work, their uses in cybersecurity, and how to generate hashes for free online.

What is a hash function and what is it used for

A hash function is a mathematical algorithm that takes any amount of data as input and produces a fixed-length string as output. That string is called a hash, digest, or checksum.

The fundamental properties of a good hash function are:

  • Deterministic: The same input always produces the same output. Hash "hello" a thousand times and you get the same hash a thousand times.
  • One-way: It's practically impossible to obtain the original data from the hash. You can't "unhash."
  • Avalanche effect: A minimal change in input produces a completely different hash. "hello" and "Hello" generate hashes that look nothing alike.
  • Collision resistant: It's extremely difficult to find two different inputs that produce the same hash.

Concrete example:

InputSHA-256 Hash
hello2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Hello185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
hello (again)2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Notice how "hello" and "Hello" (only the capital changes) produce totally different hashes, but "hello" repeated gives the same result. Generate your own hashes with the NexTools hash generator.

MD5: history, current use, and why it's no longer secure

MD5 (Message Digest Algorithm 5) was created by Ronald Rivest in 1991 and for years was the standard for file integrity verification. It produces a 128-bit hash (32 hexadecimal characters).

Why MD5 is no longer secure:

In 2004, researchers demonstrated that generating MD5 collisions was possible in seconds. This means two completely different files can have the same MD5 hash. In 2008, a team used this vulnerability to create a fake SSL certificate. In 2012, the Flame malware used MD5 collisions to masquerade as a Windows update.

Still-valid uses of MD5 in 2026:

  • Non-cryptographic checksums: Verifying a download wasn't corrupted during transfer.
  • Deduplication: Detecting duplicate files in a filesystem. Accidental collision probability is negligible.
  • Cache keys: Generating fast keys for hash tables in non-cryptographic applications.

NEVER use MD5 for: Storing passwords, verifying digital signatures, or any security-critical context.

SHA-256: today's security 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).

Why SHA-256 is the standard in 2026:

  • No known collisions: After 25 years, no one has found a collision in SHA-256. The search space is 2^256 possibilities — more than the atoms in the observable universe.
  • Bitcoin and blockchain: SHA-256 is Bitcoin's core hash function. Bitcoin mining consists of finding a nonce that produces a SHA-256 hash with a certain number of leading zeros. In 2026, the Bitcoin network computes approximately 600 quintillion SHA-256 hashes per second.
  • SSL/TLS certificates: All modern HTTPS certificates use SHA-256 for signing. Since 2017, browsers reject certificates signed with SHA-1.
  • Git: Git uses SHA-1 (migrating to SHA-256) to identify commits and objects.

Speed: SHA-256 is slower than MD5 (approximately 3-4x in software), which is actually an advantage for password storage — it makes brute force attacks more expensive.

Comparison: MD5 vs SHA-1 vs SHA-256 vs SHA-3

AlgorithmOutput bitsHex lengthSecure in 2026Relative speed
MD512832 charsNo (collisions in seconds)Fastest
SHA-116040 charsNo (collision demonstrated 2017)Fast
SHA-25625664 charsYesMedium
SHA-512512128 charsYesMedium (faster on 64-bit)
SHA-3256/51264/128 charsYesSlower

When to use each:

  • MD5: Only for non-cryptographic checksums and deduplication
  • SHA-1: Avoid. Only for legacy system compatibility
  • SHA-256: Default choice for all cryptographic use
  • SHA-512: When you need a longer hash or work on 64-bit architectures
  • SHA-3: Alternative to SHA-2 with a different design. Use if regulations require it

Compare different algorithms with the NexTools hash generator supporting MD5, SHA-1, SHA-256, and SHA-512.

Practical real-world uses of hashes

Hashes are in more places than you might think:

1. Password storage. Databases should NEVER store passwords in plain text. Instead, they store the hash. When you log in, the system hashes your password and compares with the stored hash. For passwords, specialized functions like bcrypt, scrypt, or Argon2 are used (adding "salt" and being intentionally slow).

2. File integrity verification. When downloading software (Linux ISOs, for example), the site publishes the file's SHA-256 hash. After downloading, you calculate the hash locally and compare. If they match, the file wasn't altered.

3. Digital signatures. Digitally signed documents use hashes. The document's hash is calculated, encrypted with the signer's private key, and attached. The recipient verifies by decrypting with the public key.

4. Blockchain and cryptocurrencies. Each block in a blockchain contains the previous block's hash, creating an immutable chain.

5. Version control (Git). Git identifies every commit, file, and directory by its SHA-1 hash.

6. Duplicate detection. Services like Google Drive or Dropbox detect duplicate files by comparing hashes instead of full content, saving space and bandwidth.

How to generate hashes: tools and code

Several ways to calculate hashes depending on your needs:

Option 1: Online tool. The NexTools hash generator calculates MD5, SHA-1, SHA-256, and SHA-512 directly in your browser. No data leaves your computer.

Option 2: Terminal.

  • Linux/Mac: echo -n "text" | sha256sum
  • MD5: echo -n "text" | md5sum
  • File: sha256sum file.zip
  • Windows PowerShell: Get-FileHash file.zip -Algorithm SHA256

Option 3: JavaScript (Node.js).

const crypto = require('crypto');
const hash = crypto.createHash('sha256').update('text').digest('hex');

Option 4: Python.

import hashlib
hashlib.sha256(b'text').hexdigest()

Remember: a hash is NOT encryption. If you need to encrypt data, use algorithms like AES. Hashes are irreversible by design. Check our guide on Base64 and encoding to understand the difference between encoding, hashing, and encryption.

Common attacks against hashes and how to protect yourself

1. Rainbow tables. Pre-computed dictionaries of hash→text for millions of common passwords. If you store a plain SHA-256 hash of "password123," an attacker finds it in the table in milliseconds. Solution: Add a "salt" (unique random value per user) before hashing.

2. Brute force. Trying all possible combinations. With MD5, a modern GPU can try 10+ billion combinations per second. With SHA-256 it's ~3 billion, and with bcrypt only ~30,000. Solution: Use slow functions (bcrypt, Argon2) for passwords, and long passwords (12+ characters).

3. Length extension attacks. Affect MD5 and SHA-256 when used directly as MAC (Message Authentication Code). Solution: Use HMAC instead of direct hash.

4. Collisions. Finding two inputs with the same hash. Already trivial for MD5, demonstrated for SHA-1 (cost: ~$100,000 in 2017). Does not exist for SHA-256. Solution: Use SHA-256 or higher.

The future of hashes: SHA-3 and post-quantum

SHA-3 (Keccak). Approved by NIST in 2015, SHA-3 uses a completely different design from SHA-2 (sponge construction vs. Merkle-Damgard). It's not a replacement for SHA-2 (which remains secure) but an alternative in case a vulnerability is ever found in SHA-2.

Quantum threat. Quantum computers could use Grover's algorithm to halve hash security. SHA-256 would go from 256-bit to 128-bit equivalent security, which is still sufficient. SHA-512 would be equivalent to 256 bits, still very secure. Migrating to SHA-256+ is prudent even without an immediate quantum threat.

BLAKE3. A more modern, extremely fast hash (up to 10x faster than SHA-256 in software) that maintains high security. Not yet a NIST standard but gaining adoption in 2026, especially in data storage and deduplication.

For most uses in 2026, SHA-256 remains the right choice. Try different algorithms with the NexTools hash generator.

Try this tool:

Open tool

Frequently asked questions

Can you reverse a hash to get the original data

No. Hash functions are mathematically irreversible (one-way functions). There's no algorithm to calculate the original data from a hash. The only option is brute force: trying inputs until one produces the same hash, which is computationally infeasible for complex data with SHA-256.

Why is MD5 no longer secure but SHA-256 is

MD5 has proven collision vulnerabilities: two different documents with the same MD5 hash can be generated in seconds on normal hardware. SHA-256 has no known collisions after 25 years of analysis. SHA-256's search space (2^256) is astronomically larger than MD5's (2^128).

What is a salt in the context of hashes

A 'salt' is a unique random value added to each password before hashing. For example: SHA-256('random123salt' + 'password') produces a unique hash even if two users have the same password. This invalidates rainbow tables and forces attackers to attack each hash individually.

What is the difference between hashing and encryption

Encryption is reversible (you can decrypt with the correct key); hashing is not. Encryption protects confidentiality (reading data); hashing protects integrity (verifying data wasn't modified). You encrypt a message so only the recipient reads it; you hash a file to verify it wasn't altered during download.

How long would it take to break a SHA-256 hash by brute force

With current technology, complete brute force of SHA-256 (trying all 2^256 combinations) would take longer than the age of the universe, even using all the world's computers. However, if the input is a weak password like '123456', an attacker can find it quickly using dictionaries. Security depends on the input's entropy.

Bitcoin uses SHA-256 — if SHA-256 breaks does Bitcoin collapse

Partially. If an efficient way to generate SHA-256 collisions were found, it would affect mining and blockchain integrity. However, Bitcoin addresses also use RIPEMD-160 and ECDSA, so breaking SHA-256 alone wouldn't directly compromise funds. The community would migrate to a new algorithm before the threat became critical.