What Is a Hash? SHA-256 vs SHA-1 vs MD5, Examples and Security
Updated: November 6, 2026 · AracMerkezi
▶ Open SHA Hash Generator (SHA-1/256/384/512)
A hash is a one-way operation that turns data of any length into a fixed-length "fingerprint": the same input always gives the same digest, and you cannot go from the digest back to the input. This guide compares MD5, SHA-1 and SHA-256 not as concepts but with real outputs and numbers: digest lengths, a measure of the avalanche effect, why collision attacks relate to half the bit length, and why a plain hash is not enough for storing passwords. The digests in the examples were produced and verified with Python hashlib.
Real outputs
Digests of the text abc:
| Algorithm | Digest (hexadecimal) | Length |
|---|---|---|
| MD5 | 900150983cd24fb0d6963f7d28e17f72 | 32 characters, 128 bits |
| SHA-1 | a9993e364706816aba3e25717850c26c9cd0d89d | 40 characters, 160 bits |
| SHA-256 | ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad | 64 characters, 256 bits |
The SHA-256 digest of empty text is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855; so "nothing" also produces a digest. Each hexadecimal character carries 4 bits, so 64 characters equal 256 bits.
Example 1: Measuring the avalanche effect
Only the last letter differs between abc and abd.
abc→ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adabd→a52d159f262b2c6ddb724a61840befc36eb30c88877a4030b65cbe86298449c9- The two digests differ in 122 of 256 bits (47.7%).
Two random digests are expected to differ in about half, that is 128 bits; a one-letter change actually produced this. Now a case difference: the digest of merhaba starts with 4c6bcdd55f3153e1… and the digest of Merhaba with 7fdc9f4717c5fe66…. This is why a hash does not bring "almost identical" data close together.
Example 2: Verifying a downloaded file
If a publisher has published the SHA-256 digest of a file, you compute it on your own machine and compare.
- On the command line run
sha256sum file.isoon Linux, orshasum -a 256 file.isoon macOS. - Compare the resulting 64 characters with the publisher's.
- If even one character differs, the file is corrupted or has been altered; download it again.
This method is meaningful only if the digest itself came from a trustworthy channel (the publisher's own page); if you take both the digest and the file from the same alterable place, an attacker can change both.
Example 3: Collisions and the birthday bound
Two different inputs giving the same digest is called a collision. For a random n-bit digest, the number of attempts needed to find a collision is about 2^(n/2) (the birthday paradox).
- MD5: 2^(128/2) = 2^64 ≈ 18.4 × 10¹⁸ attempts; moreover, structural weaknesses have pulled this far lower, so MD5 should not be used for security.
- SHA-1: the bound was 2^80; because practical collision attacks have been demonstrated, it is not recommended for security purposes.
- SHA-256: 2^128 ≈ 3.40 × 10³⁸ attempts; not practical today.
These are theoretical bounds; what matters most is whether the algorithm has a known attack. So if you are designing a new system, do not pick older algorithms unless compatibility requires it.
Example 4: A password stored with a plain hash
Suppose a site stores 8-digit numeric PINs with plain SHA-256. The number of possible values is 10⁸ = 100,000,000. With hypothetical hardware that can compute 10 billion digests per second: 10⁸ / 10¹⁰ = 0.01 seconds. Even for an 8-character letters-and-digits password (62⁸ ≈ 218,340,105,584,896 possibilities) it takes 6.1 hours. This is why fast digests are inadequate for storing passwords: speed helps the attacker, not the defender.
Example 5: Fixed length and the role of salt
- The SHA-256 digest of a million
acharacters is also 64 characters; 1 byte and 1 GB produce digests of the same length. - Suppose two users both chose the password
123456. Plain SHA-256 gives8d969eef6ecad3c2…for both; if the database leaks, users carrying the same digest are revealed to use the same password. - If a random salt is added for each user (
x7Kqandp2Zdin the example), the digests become completely different,221a30ad91f1f232…and22ef61656432a9e2…. This is only to show the concept; in real systems the salt is managed automatically by bcrypt, scrypt and Argon2.
Uses
- File integrity: Verifying that a downloaded file is not corrupted.
- Digital signatures and certificates: The digest of the document is signed, not the document itself.
- Finding duplicate data and cache keys: Because identical content gives identical digests, copies are easy to detect.
- Version control systems: Addressing objects by the digest of their content is a common method.
Hash, encryption and HMAC
- Hash: Keyless, no way back; used for integrity and verification.
- Encryption: Decrypted with a key; used when you need to store data and read it later.
- HMAC: Combines a hash with a secret key; it verifies a message's authenticity and who it came from. For the key
anahtarand the textmesaj, HMAC-SHA256 is4efc48e22c0421d2f0be62f9369b7930b6b69d9e71ee42a02f25ceb35c441b9c.
What is used for storing passwords?
Instead of plain SHA-256, salted (a random extra value per password) and deliberately slow algorithms are used: bcrypt, scrypt or Argon2. The salt prevents identical passwords from producing identical digests and defeats precomputed tables; slowness lowers the attacker's guessing speed.
Which one to choose and when?
| Need | Suitable choice |
|---|---|
| File integrity | SHA-256 |
| Password storage | bcrypt, scrypt, Argon2 |
| Message authentication | HMAC-SHA256 |
| Non-security cache key | MD5 would do, but SHA-256 is preferred |
Common mistakes
- Mistaking a hash for encryption; there is no way back.
- Storing a password with plain SHA-256 or MD5.
- Taking both the file and its digest from the same untrusted source.
- Missing differences in case and whitespace;
abcandabc(trailing space) give completely different digests. - Comparing a hexadecimal digest while ignoring letter case and thinking it is "different"; the letters A–F may be written in upper or lower case.
- Using MD5 in a digital signature without knowing about its collision weakness.
- Truncating a digest and comparing only its first few characters; the collision probability rises quickly in a truncated digest.
- Writing your own hash algorithm; use proven, public algorithms.
- Treating a hash value as secret information: the digest of short, predictable input can be found with a dictionary.
For text, the SHA Hash Generator tool computes SHA-1, SHA-256, SHA-384 and SHA-512 digests in your browser. On passwords see the Secure Password Guide and the Password Strength Checker.
Note: The security information is general; consult current guidelines for system design.
Frequently asked questions
Can a hash be reversed?
No. A hash is one-way; the original data cannot be recovered from the digest. It can only be guessed by trying possible inputs and comparing digests, which is why slow algorithms are needed to store passwords.
Is MD5 still secure?
Not for security purposes. Collision attacks have been demonstrated against MD5. For file integrity and signatures use a current algorithm such as SHA-256.
Is SHA-256 enough for storing passwords?
Plain SHA-256 is not enough; it is computed so fast that it is quickly brute-forced. Use salted, slow bcrypt, scrypt or Argon2.
Tools mentioned in this guide
More guides
- How to Create a Secure Password: Length, Entropy and 8 Rules – How to create a secure password: password strength in bits, random-word passphrases, command-line generation and eight practical rules.
- What Are JSON, Base64 and URL Encoding? Encoding vs Encryption vs Hashing – What do JSON, Base64, URL encoding, HTML entities, SHA and JWT do? Encoding vs encryption vs hashing, with examples that were run and verified.
- How to Convert HEX to RGB Color Codes: Step-by-Step Examples – How to convert a HEX color code to RGB and back: hexadecimal basics, short and 8-digit HEX, darkening math and verified JavaScript and Python snippets.
- What Is a JWT (JSON Web Token) and How Does It Work? Decoding, Signature and Security – What is a JWT, how do you decode it and verify its signature? A real sample token, exp time math, a tampering test and security mistakes.
- How Are Random Numbers Generated? Range Mapping, Repeat Probability and Fair Draws – How are random numbers generated and how do you hold a fair draw? Range-mapping formula, repeat probability, combination math and official-draw warnings.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.