Skip to main content
Tools Star Hub

Developer Tools

MD5 vs SHA-256: Which Hash Should You Use?

By Tools Star Hub Editorial Team · Published

Quick answer: use SHA-256. MD5 produces a 128-bit hash (32 hex characters) and has known collision attacks, so RFC 6151 says it is not prudent to use MD5 when collision resistance is required, such as for digital signatures or certificates. SHA-256, defined by NIST in FIPS 180-4, produces a 256-bit hash (64 hex characters) and has no practical collision attack. MD5 still turns up as a quick checksum in older systems, but it should not protect anything an attacker might tamper with. The Hash Generator offers SHA-256, SHA-384 and SHA-512 through the browser's Web Crypto API, and deliberately does not offer MD5.

Hashes are used to check downloads, detect duplicate files, sign software and store fingerprints of data. Choosing a weak one can let a forged file pass as genuine. Knowing the difference also helps you read older documentation that still lists MD5 checksums and decide how far to trust them.

What is a hash function?

A hash function turns input of any length into a fixed-length output called a digest. The same input always gives the same digest, and a tiny change gives a completely different one. The text hello hashes to 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 with SHA-256, while Hello, with a capital H, gives 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969.

A cryptographic hash should make three things impractical: finding an input for a given digest, finding a second input with the same digest as a known one, and finding any two inputs with the same digest. The last property, collision resistance, is the one MD5 has lost.

MD5 vs SHA-256: Differences and Which Hash to Use — Tools Star Hub

How do MD5 and SHA-256 compare?

The table shows the main differences. Digest lengths come from the algorithms' definitions; the security status follows RFC 6151 for MD5 and FIPS 180-4 for SHA-256.

MD5 vs SHA-256
PropertyMD5SHA-256
Digest size128 bits256 bits
Hex length32 characters64 characters
Hash of hello5d41402abc4b2a76b9719d911017c5922cf24dba…938b9824
Collision resistanceBroken; practical attacks publishedNo practical attack known
StandardRFC 1321, updated by RFC 6151NIST FIPS 180-4
In browser Web CryptoNot availableAvailable

Why is MD5 considered broken?

Researchers have shown how to build two different inputs with the same MD5 digest. Once collisions can be made on demand, an attacker can prepare a harmless file and a harmful one that share a hash, get the harmless one approved or signed, and swap in the other. RFC 6151 replaced MD5's security considerations for this reason.

The RFC also notes that the attacks affect some uses more than others. Using MD5 inside HMAC for message authentication was not immediately broken by the published attacks, but new designs should not choose MD5 at all.

Where is MD5 still used?

You will still see MD5 checksums next to downloads, in older databases and in tools that detect duplicate files. For catching accidental corruption, such as a file damaged during a copy, MD5 still notices the change. What it cannot do is prove that nobody tampered with the file on purpose.

If a download page offers both MD5 and SHA-256 values, check the SHA-256 one. If it only offers MD5, treat the check as protection against accidents, and prefer a signed release or an official SHA-256 checksum when the file matters.

What about SHA-384 and SHA-512?

SHA-384 and SHA-512 belong to the same SHA-2 family as SHA-256, defined in FIPS 180-4. They give longer digests, 96 and 128 hex characters. For most checksums and fingerprints, SHA-256 is the common choice because it is widely supported and its 64-character value is easier to compare.

MDN's documentation for the Web Crypto digest function lists SHA-1, SHA-256, SHA-384 and SHA-512 as the supported algorithms, and warns that SHA-1 should not be used in cryptographic applications. MD5 is not part of the API, which is why the Hash Generator offers only the SHA-2 options.

Should I hash passwords with MD5 or SHA-256?

Neither on its own. Both are designed to be fast, which helps attackers try billions of guesses. Passwords should be stored with a slow, salted password-hashing function such as Argon2, bcrypt or scrypt, using a well-maintained library.

Use SHA-256 for data fingerprints, checksums and building blocks inside protocols, not as a direct password store.

How do I compare two hashes reliably?

Compare the whole value, not just the first and last few characters. Copying both values into a text editor on separate lines, or pasting one into your browser's find box while viewing the other, makes a mismatch easy to spot. Watch for extra spaces or line breaks that slipped in while copying, because the Hash Generator hashes exactly the text you give it, including whitespace.

If the values differ, do not assume the published hash is wrong. Download the file again from the official source and re-check. A mismatch can mean a corrupted download, a different version of the file, or a file that has been changed. Only use the file once the SHA-256 values match exactly.

How do I move an old system from MD5 to SHA-256?

Start by listing where MD5 is used and why. Checksums published for downloads can usually switch straight to SHA-256 by publishing the new value alongside the old one for a while. Database columns that store MD5 fingerprints need to grow from 32 to 64 characters and be recalculated from the original data.

Anything security-related, such as signatures, tokens or certificate fingerprints, should move first, because that is where collisions do real harm. Passwords stored as MD5 hashes need a different plan: re-hash them with a proper password-hashing function when each user next signs in, rather than switching to plain SHA-256.

Document the change. Anyone verifying files needs to know which algorithm the published value uses, so label checksums clearly, for example SHA-256 followed by the value.

How can I tell which algorithm made a hash?

The length is the main clue. A 32-character hex value is usually MD5, 40 characters suggests SHA-1, 64 characters suggests SHA-256, 96 characters SHA-384 and 128 characters SHA-512. The length alone cannot prove the algorithm, because other functions share some of these sizes, so check the documentation that came with the value.

If you have the original data, hash it with each candidate algorithm and see which result matches. This is a quick way to confirm which function a system uses before migrating it.

How do I check a file or text with SHA-256?

  1. Get the published hash. Copy the SHA-256 value from the official source, such as the vendor's download page.
  2. Hash your copy. Paste the text into the Hash Generator and choose SHA-256, or use your operating system's checksum command for a file.
  3. Compare every character. The two 64-character values must match exactly. One different character means different data.
  4. Do not fall back to MD5 for security. If only MD5 is offered, treat it as a corruption check, not proof of authenticity.

Example

One letter changes everything

hello and Hello give completely different SHA-256 values, so even a small edit is obvious.

MD5 checksum on an old download

5d41402abc4b2a76b9719d911017c592 is the MD5 of hello: it catches corruption but cannot prove the file was not swapped.

Choosing a longer digest

SHA-512 produces a 128-character value when a protocol or policy asks for it.

What should I keep in mind?

Hashing is not encryption

A hash cannot be reversed to get the input back; encryption is designed to be reversed with a key.

Encoding matters

The digest is of the exact bytes. Different line endings or a trailing space give a different hash.

Case of hex

Hex digests are usually lowercase, but uppercase and lowercase represent the same value.

Local processing

The Hash Generator runs in the browser using Web Crypto.

FAQ

Is MD5 still safe for checksums?
For spotting accidental corruption it still works. For proving a file has not been deliberately altered, use SHA-256 or a signed release.
How long is a SHA-256 hash?
256 bits, written as 64 hexadecimal characters.
How long is an MD5 hash?
128 bits, written as 32 hexadecimal characters.
What is a hash collision?
Two different inputs that produce the same digest. Practical collisions exist for MD5 but not for SHA-256.
Which SHA-2 variant should I pick?
SHA-256 for most uses. Choose SHA-384 or SHA-512 when a protocol, policy or tool specifically asks for the longer digest.
Why doesn't the Hash Generator offer MD5?
It uses the browser's Web Crypto API, which supports the SHA family and not MD5, and MD5 should not be used for new security work.
Is SHA-1 better than MD5?
SHA-1 also has practical collision attacks and MDN warns against using it in cryptographic applications. Use SHA-256 instead.
Does a longer hash mean more security?
Generally a longer digest from a sound algorithm resists collisions better, but the algorithm's design matters as much as the length.
Can two files have the same SHA-256 hash?
In theory yes, because the output is fixed-length, but no one has found a SHA-256 collision in practice.
What is HMAC?
A way to combine a hash with a secret key to authenticate a message. Modern HMACs use SHA-256 or another SHA-2 function.
Why do download pages still show MD5 sums?
Legacy habit and speed—prefer SHA-256 when both are published, especially for security-sensitive files.
Can I truncate a SHA-256 digest safely?
Shorter prefixes raise collision risk; keep the full hex string for verification.
Does hashing encrypt my file?
No—hashes are one-way fingerprints. Anyone can recompute them from the same bytes.
How do salted passwords relate to SHA-256?
Password storage needs slow KDFs (bcrypt, scrypt, Argon2), not a bare SHA-256 of the password.
What is a rainbow table in this context?
Precomputed hash lookups for common inputs; salts and slow hashing defeat them.
Is SHA-512 always stronger than SHA-256?
SHA-512 has a larger digest; for most file integrity checks SHA-256 is already standard and sufficient.
Can hardware acceleration change the hash value?
No—correct implementations must match the same digest regardless of CPU instructions used.
How should I compare two digests visually?
Compare full strings case-insensitively; do not stop at the first few hex characters.
Does zip compression alter a file’s hash?
Yes if bytes change. Hash the exact artifact you distribute, not an unrelated archive layout.
Why might Git show a different checksum concept?
Git object IDs hash content with headers; they are not raw MD5/SHA-256 of the working-tree file alone.

Generate a SHA-256, SHA-384 or SHA-512 hash in the Hash Generator.

To create strong passwords, use the Password Generator.

To encode binary data as text, use the Base64 Encoder.

For data format basics, read JSON vs XML vs YAML.

Sources and further reading