Skip to content
OEWER Tools
How-To

What Is a Hash? SHA-256 vs SHA-1 Explained

4 min readBy OEWER Team

What a cryptographic hash does, why SHA-256 is preferred to SHA-1, how to check a download against a published hash, and why hashes alone are wrong for storing passwords.

In this article
  1. What a hash does
  2. The SHA family
  3. Checking a download
  4. Text is hashed as bytes
  5. Not for passwords
  6. Hash is not encryption
  7. A short checklist
  8. Sources

A hash is a fixed-length fingerprint of some data. Change one letter of the input and the fingerprint changes completely. Hashes are used to check downloads, detect changes and sign data. This guide explains what a hash is, the differences between SHA-1 and SHA-256, how to compare a file with a published hash, and the one job a plain hash must not be used for: storing passwords.

What a hash does

A cryptographic hash function takes input of any size and returns a short value of fixed size. It has a few key properties. The same input always gives the same output. A small change to the input changes the output beyond recognition. It is practical to compute in one direction and infeasible to work backwards from the output to the input. And it is infeasible to find two different inputs with the same output.

The SHA-256 hash of the text abc is ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad, and the hash of abd shares nothing with it. The hash of empty text is also well defined: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.

The SHA family

The browser can compute four hashes: SHA-1, SHA-256, SHA-384 and SHA-512. The number is the size of the output in bits, apart from SHA-1, which has 160 bits. SHA-256 gives 64 hex digits and SHA-512 gives 128. SHA-256 is the usual choice today. SHA-1 is considered broken for security because researchers produced two different files with the same SHA-1 hash in 2017, NIST has deprecated it and plans to phase it out by 2030, and MDN warns against using it for cryptographic purposes. It still appears in older systems and for non-security checksums.

Checking a download

Software sites often publish a hash next to a download. After downloading, you compute the hash of your copy and compare. If the values match, the file is the one that was published. If they differ, the download was damaged, or the file has been changed. The tool on this site has a field for pasting a published hash and says whether it matches. It compares ignoring case and spaces. Remember that the check is only as trustworthy as the place you got the published hash from: a hash on the same page as a tampered file proves little.

Text is hashed as bytes

A hash works on bytes, not letters. The tool converts your text to UTF-8 bytes first, which is what most programs do. A different text encoding, a trailing newline or a different line ending gives a different hash for text that looks the same. This is the most common reason that a hash made here differs from one made by a command-line program. The words hello and hello followed by a newline have different hashes.

Not for passwords

Plain hashes such as SHA-256 are designed to be fast. That is the opposite of what is needed to protect passwords. An attacker who steals a table of SHA-256 password hashes can try billions of guesses per second on ordinary hardware, and will find every short or common password. Password storage needs a deliberately slow function with a random salt, such as Argon2, scrypt, bcrypt or PBKDF2. If you build a website that stores passwords, use one of those from a trusted library, not a bare hash.

Hash is not encryption

A hash cannot be reversed to get the original text back, so it is not a way to store a message for later. Encryption is reversible with a key. A hash is a one-way fingerprint. Short or guessable inputs can still be found by trying candidates, which is why hashes of simple words are easy to look up.

A short checklist

  • Use SHA-256 or longer for new work. Use SHA-1 only to match an older system.
  • Compare the full hash, not the first few characters.
  • Get the expected hash from a trusted source.
  • Watch for different line endings and text encodings.
  • Never store passwords as a plain hash.

Sources

This article was written with AI assistance. How we research and check our articles.

Share

Email

Keep reading