TR

Home / Guides / What Is a Hash? SHA-256 vs SHA-1 vs MD5, Examples and Security

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:

AlgorithmDigest (hexadecimal)Length
MD5900150983cd24fb0d6963f7d28e17f7232 characters, 128 bits
SHA-1a9993e364706816aba3e25717850c26c9cd0d89d40 characters, 160 bits
SHA-256ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad64 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.

  1. abc → ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
  2. abd → a52d159f262b2c6ddb724a61840befc36eb30c88877a4030b65cbe86298449c9
  3. 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.

  1. On the command line run sha256sum file.iso on Linux, or shasum -a 256 file.iso on macOS.
  2. Compare the resulting 64 characters with the publisher's.
  3. 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).

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

Uses

Hash, encryption and HMAC

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?

NeedSuitable choice
File integritySHA-256
Password storagebcrypt, scrypt, Argon2
Message authenticationHMAC-SHA256
Non-security cache keyMD5 would do, but SHA-256 is preferred

Common mistakes

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

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.