Hash Functions and Cryptography: MD5, SHA1, SHA256 Compared and Explained

Published July 13, 2026

Cryptography Basics

Cryptography uses mathematical techniques to protect information, verify identity, and detect tampering. Hash functions sit beside encryption and digital signatures in that toolkit, but they solve a different problem. A hash function creates a fixed-size digest from input data. It does not hide the input so it can be decrypted later; instead, it creates a repeatable fingerprint that can be compared with another fingerprint.

What is a Hash Function?

A hash function accepts data of almost any size and returns a digest of a specific length. SHA-256, for example, returns 256 bits, commonly written as 64 hexadecimal characters. The same input should always create the same digest. If the input changes by one byte, a secure hash function should produce a digest that looks unrelated to the previous one.

Properties of Secure Hashes

Secure cryptographic hashes are designed for pre-image resistance, second pre-image resistance, and collision resistance. In practical terms, it should be infeasible to recover an input from its digest, infeasible to find a different input with the same digest as a known input, and infeasible to find any two inputs that collide. These properties are why hash functions are useful in certificates, software releases, audit logs, and signing workflows.

MD5: Legacy Algorithm

MD5 produces a short 128-bit digest and is still seen in older checksum lists because it is fast and widely implemented. It is no longer appropriate for cryptographic trust decisions. If you are checking whether a casual file transfer completed without accidental corruption, MD5 may match a legacy publisher value, but it should not be used to protect software updates, certificates, password storage, or signatures.

MD5 Vulnerabilities

The central problem with MD5 is practical collision creation. Attackers have demonstrated ways to create different inputs with the same MD5 digest. Once collisions become practical, the digest can no longer act as reliable evidence that a file or document is unique and unchanged in adversarial conditions.

SHA1: Deprecated

SHA-1 produces a 160-bit digest and was once common in certificates, source control, package signing, and old APIs. It is now deprecated for security-sensitive use. You may still need SHA-1 to compare against an old manifest, but new systems should choose SHA-256 or stronger members of the SHA-2 family.

SHA-1 Attacks

SHA-1 attacks lowered confidence in its collision resistance. A collision does not mean every SHA-1 checksum is instantly useless for accidental corruption checks, but it does mean SHA-1 should not be trusted when an attacker can choose or influence the content being hashed.

SHA256: Current Standard

SHA-256 is the most practical default for modern checksum work. It is supported by browsers, operating systems, package managers, cloud tools, and security libraries. For file verification, release manifests, and most audit references, SHA-256 gives a strong balance of compatibility, digest size, and security margin.

SHA512: Extended Security

SHA-512 returns a longer 512-bit digest. It is useful when a standard or internal policy requires it, and it can perform well on 64-bit platforms. The output is longer, which makes it less convenient for manual comparison, but it provides a larger digest space.

Collision Resistance

Collision resistance matters whenever the digest is used as evidence. If two files can be crafted to share a digest, a malicious file could be substituted for a trusted one. Stronger algorithms make that attack impractical with current public techniques.

Pre-Image Resistance

Pre-image resistance means an observer should not be able to take a digest and calculate an input that produces it. This is important for password verification, but plain fast hashes are still not sufficient for password storage because attackers can test guesses quickly. Password systems need slow, salted password hashing functions.

Hash Algorithm Comparison Table

Use MD5 only for matching legacy non-security checksums, SHA-1 only for old compatibility requirements, SHA-256 for most current integrity workflows, and SHA-512 where a longer SHA-2 digest is required. When in doubt, choose SHA-256 for checksums and choose a dedicated password hashing function for passwords.

← Back to Blog | Go to Tool →