Hashing is one of the quiet foundations of modern computing. It protects passwords, verifies downloads, powers version control and secures digital signatures. Yet many people confuse hashing with encryption. This guide explains what a hash is, how the common algorithms differ, and how to use them correctly.
What Is a Hash Function?
A hash function takes any input, from a single word to a multi-gigabyte file, and produces a fixed-length string called a hash, digest or checksum. A good cryptographic hash has several important properties:
- Deterministic. The same input always produces the same output.
- Fast to compute. Generating a hash from any input takes very little time.
- One-way. You cannot work backwards from the hash to recover the original input.
- Avalanche effect. Changing even one character completely changes the hash.
- Collision resistant. It should be practically impossible to find two different inputs with the same hash.
Hashing vs. Encryption
Encryption is reversible: with the right key you can turn encrypted data back into the original. Hashing is not reversible. You use encryption when you need to get the data back later, and hashing when you only need to verify that something matches or has not changed.
Comparing Common Algorithms
MD5
MD5 produces a 128-bit hash and was once extremely popular. It is now considered broken for security purposes because collisions can be created easily. It is still sometimes used as a quick checksum to detect accidental corruption, but not for anything security related.
SHA-1
SHA-1 produces a 160-bit hash. In 2017, researchers publicly demonstrated a practical collision, and major browsers and certificate authorities have since moved away from it. Avoid it for new projects.
SHA-256 and SHA-512
These belong to the SHA-2 family. SHA-256 produces a 256-bit hash, shown as 64 hexadecimal characters, while SHA-512 produces a 512-bit hash with 128 hexadecimal characters. Both are widely trusted today and are the usual choice for file integrity, digital signatures and many other applications.
Real-World Uses of Hashes
- Verifying downloads. Software publishers often list a SHA-256 checksum next to a download link. After downloading, you hash the file and compare. If the values match, the file arrived intact and unmodified.
- Detecting changes. Version control systems and backup tools use hashes to see whether a file has changed.
- Digital signatures. Instead of signing a whole document, systems sign its hash, which is faster and just as secure.
- Deduplication. Storage systems compare hashes to find identical files without reading every byte.
A Warning About Passwords
Never store passwords using a plain, fast hash such as SHA-256 on its own. Fast hashes allow attackers to test billions of guesses per second. Use a purpose-built password hashing algorithm such as Argon2, bcrypt or scrypt, which are deliberately slow and include a unique random salt for each user. In PHP, the built-in password_hash() and password_verify() functions handle this correctly.
How to Check a File Hash
- Download the file and find the checksum published by the source, ideally on an official HTTPS page.
- Generate the hash of your downloaded file using the same algorithm.
- Compare the two values carefully. They must match exactly.
You can generate SHA-1, SHA-256 and SHA-512 hashes of text and files instantly with our Hash Generator. It uses the Web Crypto API built into your browser, so your input stays on your device.
Final Thoughts
A hash is a digital fingerprint. Use SHA-256 or SHA-512 when you need to confirm integrity, avoid MD5 and SHA-1 for anything security related, and never use a plain fast hash to store passwords. Understanding these basics will help you make safer choices in everyday work.