What Is a Hash? MD5 vs SHA-256 and When to Use Each
Security Tools

What Is a Hash? MD5 vs SHA-256 and When to Use Each

What a Hash Actually Is

A cryptographic hash function is a one-way machine: you feed it data of any size — a word, a document, a multi-gigabyte disk image — and it returns a fixed-length string of characters called a digest. The digest is deterministic (the same input always yields the same output) and it is a fingerprint of the data, not a copy of it. You cannot run the machine backwards to recover the input from the digest. If you want to try any of this as you read, open the Hash Generator in another tab and hash a few phrases.

Two properties make hashes useful. First, the output length is fixed regardless of input size: MD5 always produces 128 bits, SHA-256 always 256 bits. Second, the output is highly sensitive to the input — change a single character and the entire digest changes unpredictably. This "avalanche effect" is what lets a hash act as a tamper-evident seal on data.

A Quick Example of the Avalanche Effect

Hash the word hello with SHA-256 and you get 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. Hash Hello — capital H — and you get something completely different, with no visual relationship to the first. There is no "close": a one-bit change to the input scrambles roughly half the output bits. That is precisely why a hash is a good integrity check. If two files have the same SHA-256 digest, they are — for all practical purposes — the same file, byte for byte.

The Main Algorithms, Briefly

MD5 (128-bit)

MD5 is fast, produces a short 32-character hex digest, and is everywhere in legacy systems. It is also cryptographically broken. Researchers demonstrated practical collisions — two different inputs with the same digest — back in 2004, and today anyone with a laptop can generate them. That makes MD5 unsafe for anything an attacker might target: certificates, signatures, or verifying a file came from a trusted source. It is still fine for non-adversarial uses like spotting accidental duplicate files or catching a corrupted transfer where no attacker is involved.

SHA-1 (160-bit)

SHA-1 was the workhorse for years but is now in the same category as MD5. In 2017 a team from Google and CWI Amsterdam produced two different PDFs with an identical SHA-1 hash (the "SHAttered" attack), and the cost of such attacks has only fallen since. TLS certificate authorities and browsers have abandoned it. Git historically used SHA-1 for object identifiers and is migrating to SHA-256. Use SHA-1 only for legacy interoperability, never for new security work.

SHA-256 and SHA-512 (SHA-2 family)

These are the current standard, defined by NIST in FIPS 180-4. SHA-256 emits a 64-character hex digest and SHA-512 a 128-character one. Both are collision-resistant with no practical attacks, and they secure TLS, code signing, cryptocurrencies, and software distribution. When security matters and you are choosing today, pick SHA-256 or SHA-512. SHA-512 is not meaningfully "safer" for typical needs — it is wider, and on 64-bit CPUs can actually run faster than SHA-256.

MD5 vs SHA-256: The Practical Comparison

People search "MD5 vs SHA-256" usually to answer one question: which should I use? The short version is that they solve overlapping problems with very different security. MD5 is faster and shorter, which is why it lingers in checksums and older protocols. SHA-256 is slightly slower and produces a longer digest, but it is collision-resistant, which MD5 is not. For any purpose where someone might deliberately try to forge a match — verifying downloads from the internet, signing, deduplication in a security-sensitive context — SHA-256 is the correct choice and MD5 is a liability. For a purely local sanity check that a file copied correctly on your own machine, MD5's speed is harmless. When in doubt, default to SHA-256; the performance difference is irrelevant for anything short of hashing terabytes.

Hashing Is Not Encryption

This trips up a lot of people, so it is worth stating plainly: hashing and encryption are different tools for different jobs. Encryption is reversible — with the right key, ciphertext turns back into the original plaintext. Hashing has no key and is not reversible; there is no "decrypt this SHA-256" operation, and any site claiming to do so is really just looking your digest up in a precomputed table of common inputs. When you see a digest, you cannot get the data back from it. What an attacker can do is guess: hash billions of candidate inputs and check for a match. That single fact drives the most important practical rule about hashes and passwords.

What Is a Hash? MD5 vs SHA-256 and When to Use Each

Why You Must Not Store Passwords With a Plain Hash

Because MD5, SHA-1, and SHA-256 are fast, they are the wrong tool for password storage. An attacker who steals a database of SHA-256 password hashes can try billions of guesses per second on commodity GPUs, cracking weak and medium-strength passwords quickly. The defense is a purpose-built password-hashing function — bcrypt, scrypt, or Argon2 — that is deliberately slow and memory-hard, plus a unique random salt per user so identical passwords do not share a digest. If you are building authentication, reach for Argon2id, not SHA-256. Use the general-purpose SHA family for integrity and fingerprinting, and if you are generating credentials to store, do it with a strong password generator and keep them in a password manager.

The Everyday Use: Verifying a Download

The most common reason to reach for a hash generator is checking that a download is intact and authentic. A reputable project publishes the SHA-256 checksum of each release next to the download link. After downloading, you hash the file yourself and compare. If the two digests match character for character, the file you have is byte-identical to the one the project published — a truncated download or a tampered file would produce a different digest. To do this here, open the Hash Generator, switch to the File tab, choose the downloaded file, and compare the SHA-256 output to the published value. Prefer SHA-256 over any MD5 the project might also list, since a matching MD5 can, in principle, be forged.

One caveat: a checksum published on the same page as the download only protects against accidental corruption and transport errors, because an attacker who could replace the file could also replace the checksum. For stronger guarantees, projects publish a signed checksum file (using GPG) so you can verify both integrity and authorship. The hash comparison is still a valuable first line of defense and catches the overwhelmingly common case of a bad or interrupted download.

How Big Is 2²⁵⁶? Why Collisions Don't Happen by Accident

People sometimes worry that two ordinary files might randomly share a SHA-256 digest. In practice this never happens by chance, and the reason is the sheer size of the output space. SHA-256 has 2²⁵⁶ possible digests — a number with 78 digits, larger than the estimated count of atoms in the observable universe. Even the famous "birthday paradox," which says collisions become likely after roughly the square root of the space, still leaves SHA-256 needing about 2¹²⁸ hashed items before an accidental collision becomes probable. At a billion billion hashes per second, that is far longer than the age of the universe. So when we say SHA-256 is "collision-resistant," part of that is mathematics (no shortcut is known) and part is simply scale: brute force is hopeless. The broken algorithms failed not because the space is small but because clever mathematical shortcuts were found that sidestep brute force entirely — which is exactly what "broken" means for a hash.

A Short History of Hash-Function Breaks

The lifecycle of a hash function is worth understanding because it explains why today's safe choice can become tomorrow's legacy algorithm. MD5 was published in 1991 and trusted through the 1990s; by 2004 researchers found full collisions, and by 2008 they used the weakness to forge a rogue certificate authority. SHA-1, standardized in 1995, was theoretically weakened through the 2000s and definitively broken in 2017 with SHAttered. Each time, there was a gap of years between "theoretically weak" and "practically exploited," during which cautious engineers had already migrated. SHA-2 (including SHA-256 and SHA-512) has held up since 2001 with no practical weakness, and SHA-3 — a structurally different design chosen through a public competition in 2015 — exists as a ready alternative should SHA-2 ever falter. The lesson for practitioners is simple: prefer the current standard, keep an eye on cryptographic news, and design systems so the hash algorithm can be swapped without a rewrite.

Digest Lengths at a Glance

It helps to recognize the algorithms by the length of their hex output, because the character count alone often tells you what you are looking at. MD5 is 32 hex characters (128 bits). SHA-1 is 40 characters (160 bits). SHA-256 is 64 characters (256 bits), and SHA-512 is 128 characters (512 bits). If a website shows you a 64-character checksum, it is almost certainly SHA-256; a 32-character one is MD5. Knowing this at a glance makes it easy to confirm you are comparing like with like before you trust a match, and to spot when a project has quietly published a weaker digest than you would prefer to rely on.

Choosing the Right Tool, in One Sentence

Use SHA-256 (or SHA-512) for anything security-related, treat MD5 and SHA-1 as legacy checksum tools only, never store passwords with a plain hash, and remember that a hash fingerprints data but never hides or encrypts it. With those four rules you will make the right call in almost every situation — and you can confirm any of them in seconds with the Hash Generator.

← Back to Blog