What is a Hash Function?

A hash function transforms arbitrary-sized input data into a fixed-size output (hash value or digest) via a one-way function. "One-way" means recovering the original data from a hash is computationally infeasible. Identical inputs always produce identical hashes, but even a 1-bit change produces a completely different output — a property known as the Avalanche Effect.

Cryptographic hash functions must additionally satisfy collision resistance (hard to find two different inputs producing the same hash), preimage resistance (hard to find original input from hash), and second preimage resistance (hard to find a different input matching a given hash).

Algorithm Comparison

MD5 (Message Digest 5)

Designed by Ronald Rivest in 1992, producing a 128-bit (32-character hex) hash. Once widely used for its speed, collision vulnerabilities were discovered starting in 1996, and practical collision attacks were demonstrated by Chinese researchers in 2004. MD5 should no longer be used for security purposes — only for simple file identity checks or legacy system compatibility.

SHA-1 (Secure Hash Algorithm 1)

Designed by the NSA and standardized by NIST in 1995, producing a 160-bit (40-character) hash. Initially considered more secure than MD5, but Google and CWI Amsterdam demonstrated a practical collision (SHAttered attack) in 2017. Major browsers and certificate authorities now reject SHA-1 certificates. Git uses SHA-1 internally but is transitioning to SHA-256.

SHA-256 (SHA-2 Family)

Designed by the NSA and standardized by NIST in 2001, producing a 256-bit (64-character) hash. No practical collision attacks have been found to date. Used as the standard in TLS certificates, Bitcoin mining, and software signing. SHA-256 is the recommended choice for general-purpose file integrity verification.

SHA-3 (Keccak)

Selected by NIST in 2012 as an alternative to SHA-2. Built on an entirely different mathematical structure (sponge function), ensuring it remains unaffected if SHA-2 vulnerabilities are discovered. Since SHA-2 is still sufficiently secure, immediate replacement is unnecessary, but SHA-3 is worth considering for projects requiring long-term security.

Practical Applications

Software Download Verification

Publishing SHA-256 checksums alongside software releases is standard practice. Users calculate the hash of downloaded files and compare against the published checksum to verify no corruption or tampering occurred during transfer. Node.js, Python, Go, and most open-source projects provide SHA-256 checksums on release pages.

Command-line verification: Windows uses certutil -hashfile filename SHA256; macOS/Linux uses sha256sum filename or shasum -a 256 filename. For browser-based verification, use the File Hash Generator/Verifier.

Backup Integrity

Record file hashes at backup creation time and compare after restoration to detect bit rot, transfer errors, or software bugs that silently corrupt data. This is the most reliable method for detecting storage media degradation.

CI/CD Pipeline Artifacts

Record build output hashes on the build server and verify on the deployment server to detect tampering in the build-to-deploy chain. Docker image digests, npm package integrity fields, and pip hash verification all use this principle.

SRI (Subresource Integrity)

SRI is a web security feature that enables browsers to automatically verify the integrity of external JavaScript and CSS files loaded from CDNs. Adding a Base64-encoded hash to the integrity attribute on <script> or <link> tags causes the browser to block execution if the downloaded file doesn't match the expected hash. This protects against compromised CDNs serving malicious code.

Password Hashing: A Different Category

SHA-256 and MD5 are designed to be fast "general-purpose" hashes. Password storage requires intentionally slow hashes to resist brute-force attacks. Dedicated password hashing algorithms like bcrypt, scrypt, and Argon2 automatically add salt (random values) and provide configurable iteration counts. Never use SHA-256 or MD5 directly for password storage.

Verification Caveats

Algorithm match — If the official checksum is SHA-256 but you compare with MD5, it will always mismatch. Always confirm which algorithm was used.

Whitespace/newlines — Copying checksums from web pages may include invisible characters. Ensure your verification tool strips whitespace automatically.

Hash match ≠ safe file — A matching hash confirms identical content but doesn't guarantee the file is malware-free. Verify that the checksum source is an official, trusted channel.

Tools

To quickly check SHA-256, MD5, and SHA-1 hashes and compare them against official checksums, use the File Hash Generator/Verifier. To check whether two files are identical, use the File Comparison tool. All processing runs in your browser — no files are sent to any server.