Skip to content

general guide

Hash Functions Explained: What MD5 and SHA Guarantee, and Where They Stop

A hash function turns any input into a fixed-length fingerprint. The same input always gives the same output, a one-bit change rewrites roughly half the output bits, and there is no practical route back from the digest to the input. Those three properties are what make hashes useful for checksums, integrity verification, deduplication and signatures. They are also what make hashes useless for two jobs people constantly assign them: keeping a value secret so it can be recovered later, and storing a password. This guide separates what each algorithm guarantees, what has actually been broken, and which job needs a different tool entirely.

Updated December 2, 2026 · 16 questions answered

Key takeaways

  • MD5 produces 128 bits (32 hex characters), SHA-1 produces 160 bits (40 hex), SHA-256 produces 256 bits (64 hex), SHA-384 produces 384 bits (96 hex) and SHA-512 produces 512 bits (128 hex).
  • MD5 and SHA-1 are cryptographically broken: practical collisions have been demonstrated for both. They remain acceptable for detecting accidental corruption, never for signatures, certificates or tamper detection.
  • SHA-256 is the sensible default. SHA-384 and SHA-512 are not weaker or stronger in any way that matters for most uses; SHA-512 is often faster on 64-bit hardware.
  • A hash is one-way. If you need the original value back, you want encoding such as Base64, or encryption — not a hash.
  • Never store passwords with a fast hash. Use a deliberately slow key-derivation function: Argon2id, scrypt or bcrypt.
  • Hashes are computed over bytes, not over characters. The same visible text in a different encoding, or with a different newline convention, produces a different digest.

The Three Properties, and the Fourth People Assume

A cryptographic hash function is defined by three resistances. Preimage resistance: given a digest, you cannot find any input that produces it. Second-preimage resistance: given one input, you cannot find a different input with the same digest. Collision resistance: you cannot find any two distinct inputs with the same digest. The third is the weakest requirement and therefore the first to fall — which is exactly the order in which MD5 and SHA-1 broke.

The fourth property people assume is secrecy, and it is not there. A hash is deterministic and public. Anyone can hash the same input and get the same output, which is the point when you are verifying a download and a disaster when you are protecting a password. If the input space is small — a four-digit PIN, a common word, an email address — an attacker simply hashes every candidate and compares. That is a dictionary attack, and no amount of digest length prevents it.

The hash generator computes MD5, SHA-1, SHA-256, SHA-384 and SHA-512 over your text in the browser and shows each digest in hex and Base64. Nothing is uploaded, which matters because the thing people most often paste into a hash tool is a token or a secret they would rather not hand to a stranger's server.

Determinism is easy to demonstrate and worth doing once. Hash a sentence, change a single letter, hash again, and compare the two digests: they share nothing visible. That is the avalanche effect, and it is deliberate. A good hash mixes every input bit into every output bit, so a checksum can certify that not even one bit changed in transit.

Digest Widths: What the Numbers Actually Mean

The output width is fixed regardless of input size, and it determines the theoretical collision bound. Because of the birthday paradox, finding a collision in an n-bit hash takes about 2^(n/2) attempts, not 2^n. That halving is the single most important number in hash security.

Measured widths: MD5 gives 16 bytes, so 128 bits and 32 hex characters. SHA-1 gives 20 bytes, 160 bits, 40 hex characters. SHA-256 gives 32 bytes, 256 bits, 64 hex characters. SHA-384 gives 48 bytes, 384 bits, 96 hex characters. SHA-512 gives 64 bytes, 512 bits, 128 hex characters.

Apply the birthday bound and the picture is stark. MD5's collision resistance is about 2^64 operations — reachable with specialised hardware, and in practice far cheaper because the algorithm itself is broken. SHA-1's is about 2^80, which was considered safe until structural attacks reduced it dramatically. SHA-256's is about 2^128, which is not reachable by any computation humanity can currently organise.

Hex and Base64 are two renderings of the same bytes, not two different hashes. Hex uses two characters per byte and is case-insensitive by convention; Base64 uses four characters per three bytes and is shorter but case-sensitive and includes +, / and =. A 32-byte SHA-256 digest is 64 hex characters or 44 Base64 characters. When a checksum does not match, check the rendering before suspecting the data — comparing a hex digest against a Base64 one is a common and entirely avoidable false alarm. The Base64 encoder converts between them.

One more byte-level subtlety: the hash is computed over UTF-8 bytes. Two strings that look identical can differ in bytes — a composed versus decomposed accented character, a Windows CRLF versus a Unix LF, a trailing space, a byte-order mark. All of those produce completely different digests. If a checksum fails on text that looks right, compare the bytes, not the glyphs. A text diff will show the invisible difference.

MD5: Broken for Security, Still Fine for Checksums

MD5 was designed by Ronald Rivest in 1991 and published as RFC 1321. It was the workhorse checksum of the early internet and is still embedded in an enormous amount of legacy software, package metadata and file-verification plumbing.

Its collapse came in stages. In 2004 Xiaoyun Wang and colleagues demonstrated practical collision finding, reducing the work far below the birthday bound. In 2008 a group including Alexander Sotirov and Marc Stevens built a chosen-prefix collision and used it to forge a certificate authority certificate that browsers trusted — a real, demonstrated break with security consequences, not a theoretical one. Chosen-prefix collisions are strictly worse than ordinary collisions: the attacker controls both inputs' meaningful prefixes, so they can make two documents that look completely different share a digest.

What MD5 is still good for is detecting accidental corruption. If a file transferred over a network and you want to know whether a bit flipped, MD5 answers that reliably, because random corruption does not mount a structural attack. What it must never be used for is anything adversarial: signatures, certificates, tamper detection, deduplication where an attacker controls one of the inputs, or content addressing in a security boundary.

Web Crypto deliberately does not implement MD5, which is why a browser-side tool that offers it has to implement it by hand. This one does, following RFC 1321's four rounds of 16 operations with the sine-derived constants, and it reproduces all five published test vectors exactly — the empty string, "a", "abc", "message digest" and the lowercase alphabet. That verification matters: a hand-written hash that is subtly wrong produces plausible-looking digests that never match anything.

The practical rule is simple. If a legacy system hands you an MD5 and you need to compare it against the same system's MD5, use MD5. If you are choosing a digest for something new, choose SHA-256 and do not look back.

SHA-1: The Same Story, a Decade Later

SHA-1 was designed by the NSA and published in 1995 as FIPS 180-1. It produces 160 bits and was the default for TLS certificates, Git object identifiers and code signing for roughly two decades.

Wang's 2005 attack reduced collision finding to about 2^69 operations, below the 2^80 birthday bound, which was the warning. The practical break arrived in February 2017 with SHAttered, from Google and CWI Amsterdam: two distinct PDF files with the same SHA-1 digest, produced at a cost the authors estimated at around 110,000 GPU-years of equivalent computation — expensive, but within reach of a well-funded attacker. In 2020 the Shambles attack extended this to chosen-prefix collisions, the more dangerous form.

Browsers stopped trusting SHA-1 certificates in 2017. Git has been migrating to SHA-256 object identifiers. The algorithm is deprecated for every security use by every standards body that matters.

SHA-1 survives in non-adversarial niches for the same reason MD5 does: it is fast, widely implemented, and adequate for detecting accidental change. It is also still what some older APIs and HMAC constructions expect. If you are verifying a checksum a legacy system produced, match the algorithm it used. If you are designing anything, use SHA-256.

The SHA-2 family — SHA-256, SHA-384 and SHA-512, published in 2001 — has no practical collision attack. SHA-384 is SHA-512 truncated with different initial constants, which is why it is not merely "SHA-256 but longer". SHA-512 operates on 64-bit words and is frequently faster than SHA-256 on 64-bit hardware for large inputs, despite producing twice the output. Choosing SHA-512 over SHA-256 is not paranoia; it is often the performance choice.

SHA-3, standardised in 2015 from the Keccak design, uses a completely different sponge construction rather than the Merkle-Damgard structure SHA-1 and SHA-2 share. It is not a replacement for SHA-2 — both are considered secure — but a structural hedge. Web Crypto does not expose SHA-3, which is why a browser tool offers the SHA-2 family and not it.

Hashing Is Not Encryption, and Not Encoding

Three operations get conflated constantly, and the distinction decides whether a design is sound.

Encoding is a reversible representation change with no key and no secrecy. Base64 turns bytes into text so they survive a channel that only handles text. Anyone can decode it. It provides zero confidentiality, and treating a Base64 string as "encrypted" is a genuine vulnerability, not a stylistic error.

Encryption is reversible with a key. It provides confidentiality: without the key you cannot recover the plaintext. Use it when you need the original value back — a stored credential you must replay, a message you must read later.

Hashing is one-way by design. There is no key and no inverse. Use it when you need to verify that something matches without storing the thing itself, or to fingerprint data for comparison.

The consequence for passwords is direct. You cannot encrypt a password and decrypt it later, because that means your system can recover every user's password — and so can anyone who compromises it. You hash it, and compare hashes at login. But a fast hash is the wrong hash, which is the next section.

A JWT is a useful illustration of all three at once. Its header and payload are Base64url-encoded, not encrypted: anyone can read them. Its signature is a keyed hash over these bytes, which is what makes it trustworthy. The JWT decoder shows the decoded claims and lets you verify the signature separately — and the fact that decoding works without any key is precisely the point people miss when they assume a token's contents are secret.

Why a Fast Hash Is the Wrong Way to Store a Password

SHA-256 is designed to be fast. That is a virtue for checksumming a gigabyte file and a catastrophe for protecting a password, because an attacker who steals your database can try billions of candidates per second on commodity GPUs. Speed is the attack surface.

A password hash must be deliberately slow and memory-hard, so that each guess costs the attacker real time and real hardware. The current recommendations are Argon2id (winner of the Password Hashing Competition in 2015), scrypt, or bcrypt. PBKDF2 is acceptable where nothing better is available, with a high iteration count, but it is not memory-hard and GPUs attack it efficiently.

Two further requirements are non-negotiable. A unique random salt per password, stored alongside the hash, so that identical passwords produce different digests and precomputed rainbow tables are useless. And a work factor tuned so verification takes a noticeable fraction of a second on your hardware — long enough to hurt an attacker, short enough not to hurt your users.

None of MD5, SHA-1, SHA-256, SHA-384 or SHA-512 does any of this. They have no salt parameter, no cost parameter and no memory hardness. A tool that computes them is a checksum tool, and calling it a password hasher would be a dangerous mislabel. The password generator creates the secret; a proper password-hashing library in your application protects it at rest. Those are different jobs and neither substitutes for the other.

For keyed integrity — proving a message came from someone holding a shared secret — the construction is HMAC, which wraps a hash in a specific keyed structure. A bare hash of secret + message is not HMAC and is vulnerable to length-extension attacks on Merkle-Damgard hashes including MD5, SHA-1 and SHA-256. If you need message authentication, use a real HMAC implementation rather than concatenating strings.

Choosing an Algorithm: A Short Decision List

The choice is less complicated than the number of available algorithms suggests. Almost every new decision resolves to SHA-256, and the exceptions are specific.

Verifying a download against a publisher's published checksum: use whatever algorithm the publisher used. You are comparing against their value, not choosing your own security posture.

Detecting accidental corruption in your own pipeline: SHA-256. MD5 is acceptable if a legacy system requires it, and CRC32 is acceptable if you only care about random bit flips and want speed — but CRC32 is not a cryptographic hash and offers no adversarial resistance at all.

Content addressing, deduplication, cache keys, ETags: SHA-256. If an attacker can influence one of the inputs, MD5 and SHA-1 are disqualified because chosen-prefix collisions let them engineer a match.

Digital signatures, certificates, code signing: SHA-256 or better, and never MD5 or SHA-1.

Storing passwords: Argon2id, scrypt or bcrypt. Not any of the five algorithms this tool computes.

Message authentication with a shared secret: HMAC-SHA256.

Generating a unique identifier rather than fingerprinting an existing value: that is a different job. Use the UUID generator — the UUID versions guide explains why a random identifier and a deterministic digest are not interchangeable, and how name-based UUID v5 uses SHA-1 internally for a purpose where its collision weakness is not the deciding factor.

  • Match the publisher's algorithm when verifying a published checksum.
  • SHA-256 for new checksums, content addressing, cache keys and ETags.
  • SHA-256 or stronger for signatures and certificates; never MD5 or SHA-1.
  • SHA-512 when you want speed on 64-bit hardware and a wider digest.
  • Argon2id, scrypt or bcrypt for passwords — with a per-password salt and a tuned work factor.
  • HMAC-SHA256 for keyed message authentication, not a bare concatenated hash.
  • Base64 or encryption when you need the original value back; a hash cannot return it.

Frequently asked questions

The questions people ask most about hash functions: md5, sha-1 and sha-256, answered directly.

Is MD5 still safe to use?

For detecting accidental corruption, yes. For anything adversarial — signatures, certificates, tamper detection, deduplication where an attacker controls an input — no. Practical collisions were demonstrated in 2004 and chosen-prefix collisions were used to forge a trusted CA certificate in 2008.

What is the difference between MD5 and SHA-256?

Width and security. MD5 produces 128 bits and is broken; SHA-256 produces 256 bits and has no practical collision attack. SHA-256's birthday bound is about 2^128 operations versus MD5's 2^64, and MD5's structural weaknesses make its real bound far lower still.

Is SHA-1 broken?

Yes. The SHAttered attack in 2017 produced two distinct PDFs with the same SHA-1 digest, and Shambles in 2020 extended it to chosen-prefix collisions. Browsers stopped trusting SHA-1 certificates that year. It remains usable only for non-adversarial checksums.

Should I use SHA-256, SHA-384 or SHA-512?

SHA-256 is the default and interoperates everywhere. SHA-512 is often faster on 64-bit hardware for large inputs and gives a wider digest. SHA-384 is SHA-512 truncated with different initial constants, sometimes chosen to resist length-extension in specific constructions. None is meaningfully weaker than the others for general use.

Why is the same text giving a different hash?

Because hashing operates on bytes. A different character encoding, a composed versus decomposed accent, CRLF versus LF line endings, a trailing space or a byte-order mark all change the bytes and therefore the digest. Compare bytes rather than glyphs when a checksum fails.

What is the difference between hex and Base64 output?

They are two renderings of the same digest bytes. Hex uses two characters per byte; Base64 uses four per three bytes, so it is shorter but case-sensitive and includes +, / and =. A SHA-256 digest is 64 hex characters or 44 Base64 characters.

Can I reverse a hash to get the original text?

No. That is the defining property. If the input space is small, an attacker can hash every candidate and compare, which is a dictionary attack rather than a reversal. If you need the value back, use encoding or encryption instead.

Is Base64 a hash?

No. Base64 is a reversible encoding with no key and no secrecy. Anyone can decode it. Treating a Base64 string as protected is a real vulnerability.

Can I store passwords with SHA-256?

No. SHA-256 is fast, has no salt parameter and no work factor, so a stolen database can be attacked at billions of guesses per second. Use Argon2id, scrypt or bcrypt with a unique per-password salt and a tuned cost.

What is a salt and why does it matter?

A salt is a unique random value stored alongside each password hash and mixed into the computation. It makes identical passwords produce different digests and defeats precomputed rainbow tables. It is not secret; its job is uniqueness, not confidentiality.

What is the avalanche effect?

The property that changing a single input bit changes roughly half the output bits. It is deliberate, and it is what lets a checksum detect even tiny corruption. Hash a sentence, change one letter, and the two digests will share nothing visible.

Why does a browser tool implement MD5 by hand?

Because Web Crypto deliberately does not offer MD5 — it exposes SHA-1, SHA-256, SHA-384 and SHA-512 only. A hand-written implementation must be verified against the published RFC 1321 test vectors, which this one matches exactly.

What is HMAC and when do I need it?

HMAC is a keyed construction that turns a hash into a message authentication code, proving a message came from someone holding the shared secret. A bare hash of secret-plus-message is not HMAC and is vulnerable to length-extension attacks on MD5, SHA-1 and SHA-256.

Is a longer hash always more secure?

Not automatically. Security depends on the algorithm's structure, not just its width: SHA-1 is longer than MD5 and both are broken. Among unbroken algorithms, a wider digest raises the birthday bound, but SHA-256's 2^128 is already far beyond reach.

Can two different files have the same SHA-256?

In principle yes, since the input space is larger than the output space. In practice no one can find such a pair: it would take about 2^128 operations. For MD5 and SHA-1, pairs have actually been constructed.

Should I use a hash or a UUID for a unique identifier?

A UUID when you need a fresh unique value; a hash when you need to fingerprint a value you already have. Name-based UUID v5 does hash a namespace and name, but that is a specific deterministic construction, not a general checksum.