File Analysis

Understanding MD5, SHA1, SHA256

Deep dive into hashing algorithms: strengths, weaknesses, and use cases.

1 Introduction

MD5, SHA-1 and SHA-256 are the three hash algorithms you will encounter most often in cybersecurity. They all produce a fingerprint of a file, but they are not equal. Imagine different ways of taking fingerprints: some are blurry and can be faked, others are extremely precise. Some of these algorithms are broken and should no longer be trusted for security, while another remains the industry standard. Knowing the difference helps you choose the right one and read analysis reports correctly.

32 chars

MD5 hash length (128 bits)

40 chars

SHA-1 hash length (160 bits)

64 chars

SHA-256 hash length (256 bits)

2 How It Works

Use the hash calculator below to compute several hashes of the same input at once. Enter some text and notice how each algorithm produces a completely different output, of a different length. This helps you learn to recognize which algorithm was used just by looking at a hash.

Recognizing a hash by its length

The examples below are the hashes of an empty file: you will meet them often in logs, and they never point to malware.

MD5: 32 hexadecimal characters

d41d8cd98f00b204e9800998ecf8427e

SHA-1: 40 hexadecimal characters

da39a3ee5e6b4b0d3255bfef95601890afd80709

SHA-256: 64 hexadecimal characters

e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

SHA-512: 128 hexadecimal characters

cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e

Length is a strong hint, not proof: other algorithms (SHA3-256, for example) also produce 64 characters.

3 Detailed Analysis

MD5: fast but broken

Created in 1991 by Ronald Rivest. MD5 was the standard for years, but in 2004 researchers led by Xiaoyun Wang demonstrated practical collisions: two different files crafted to produce the same MD5 hash. Today an ordinary computer can generate one in seconds, and the Flame spyware (2012) used an MD5 collision to forge a Microsoft signature. MD5 must no longer be trusted for security, but it remains widely used for quick checksums and as a lookup key in malware databases.

+ Very fast + Universally supported - Collisions easy to create

SHA-1: on its way out

Designed by the NSA and published in 1995. SHA-1 was considered secure for a long time, but in 2017 Google and the CWI Amsterdam published "SHAttered": two different PDF files with the same SHA-1 hash. Even more dangerous attacks followed in 2020. Browsers and certificate authorities have dropped SHA-1, and NIST has announced its complete retirement by 2030. SHA-1 is deprecated, but still appears in legacy systems and older threat intelligence reports.

+ Still common in legacy systems - Collision demonstrated in 2017 - Rejected for certificates

SHA-256: the current standard

Part of the SHA-2 family, designed by the NSA and published in 2001. SHA-256 is today's reference in cybersecurity. No collision has ever been found, and none is expected to be feasible in the foreseeable future. It is used in TLS certificates, software signatures, Bitcoin and malware databases. When people talk about "the hash of a malware sample", they usually mean its SHA-256. Prefer SHA-256 whenever you have the choice.

+ No known collisions + Industry standard + Hardware-accelerated on most modern processors

SHA-512 and SHA-3: the alternatives

SHA-512, from the same SHA-2 family, produces a 512-bit hash (128 characters) and offers an even larger safety margin; it can be faster than SHA-256 on some 64-bit processors. SHA-3, standardized in 2015, is built on a completely different design and serves as a backup should SHA-2 ever weaken. Both are sound choices, simply less common in analysis reports.

The collision problem

A collision happens when two different inputs produce the same hash, as if two different people had exactly the same fingerprints. Mathematically, collisions are unavoidable (there are more possible files than possible hashes), but a good algorithm makes them practically impossible to find. For SHA-256, you would need about 2128 attempts, far beyond the combined power of every computer on Earth.

Comparison table

Property MD5 SHA-1 SHA-256 SHA-512
Output length128 bits160 bits256 bits512 bits
Hex characters324064128
Collision resistantNoNoYesYes
RecommendationLookup onlyLegacy onlyUse thisFine too

What about passwords?

None of these algorithms is suitable on its own for storing passwords: they are designed to be fast, which helps attackers test billions of guesses. Passwords must be stored with deliberately slow, salted functions such as Argon2, bcrypt or scrypt. More in Password security.

Try it on mlab.sh

Compute MD5, SHA-1 and SHA-256 hashes side by side for any input. See the differences in output length and format that you just learned to recognize.

Generate & compare hashes

4 Red Flags

A system relies solely on MD5 or SHA-1 for integrity

If a security tool or download site only provides MD5 or SHA-1 hashes, the check catches accidental corruption but not a deliberate forgery: an attacker can craft a file with the same hash.

Passwords stored with a fast hash

Passwords stored as plain MD5 or SHA hashes, especially without a salt, can be cracked massively with precomputed tables or graphics cards. If a service you use has leaked such hashes, change that password everywhere you reused it.

A certificate signed with SHA-1

Public certificate authorities stopped issuing SHA-1 certificates years ago, and modern browsers reject them. A website still using one is badly maintained, or not what it claims to be.

A threat report only lists MD5 hashes

A good threat intelligence report should provide at least SHA-256 hashes. MD5-only reports may point to outdated or low-quality intelligence (see Reading a file analysis report).

Someone offers to "decrypt" a hash

Hashing is not encryption: a hash cannot be decrypted. "Hash decryption" sites simply look up known values in huge tables. If a vendor talks about encrypting data with MD5, they are confusing the two concepts.

Related Modules