What Is a Hash? MD5, SHA-1 and SHA-256 Explained (and How to Verify a Download)

What Is a Hash? MD5, SHA-1 and SHA-256 Explained (and How to Verify a Download) — Preslo guide cover with the Hash Generator tool

Software download pages often list a long string of letters and numbers labelled "SHA-256" or "checksum", and most people scroll straight past it. That string is a hash, and it lets you confirm in under a minute that the file on your computer is exactly the one the publisher intended. This guide explains what hash functions are, why MD5 and SHA-1 are no longer trusted for security, how to verify a download step by step, and why hashes alone are the wrong way to store passwords.

What a hash function does

A hash function takes input of any size, whether a single word or a multi-gigabyte disk image, and produces a short output of fixed length called a hash, digest or checksum. It is usually written in hexadecimal, using the digits 0–9 and the letters a–f.

Think of it as a fingerprint for data. The fingerprint is tiny compared with the person, it is always the same for the same person, and two different people are extremely unlikely to share one. You cannot rebuild the person from the fingerprint, but you can use it to check whether two things are the same.

The properties that make a good cryptographic hash

  • Deterministic: the same input always gives the same output, on any computer, in any program.
  • Fixed length: SHA-256 always produces 256 bits (64 hex characters), whether you hash one byte or a whole film.
  • Avalanche effect: a tiny change to the input produces a completely different output.
  • One-way (preimage resistance): given a hash, there is no practical way to work out an input that produces it.
  • Collision resistance: it should be infeasible to find two different inputs with the same hash.

Collisions must exist in theory, because there are infinitely many possible inputs and only a fixed number of outputs. What matters is that nobody can find one on purpose. SHA-256 has 2 to the power of 256 possible outputs, a number with 78 digits, and no practical method of finding a collision is publicly known.

The avalanche effect in practice

Here are the SHA-256 hashes of three very similar inputs:

InputSHA-256
abcba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
abda52d159f262b2c6ddb724a61840befc36eb30c88877a4030b65cbe86298449c9
Abc06d90109c8cce34ec0c776950465421e176f08b831a938b3c6e76cb7bee8790b

One changed letter, or one capital letter, gives an unrelated result. There is no pattern that hints at how similar the inputs were. The value for abc is the official test vector from the SHA-256 standard, so you can type abc into any hash tool to confirm it is working correctly.

MD5, SHA-1 and SHA-256 compared

AlgorithmOutput sizeHex lengthStatus for security
MD5128 bits32 charactersBroken: collisions can be created deliberately
SHA-1160 bits40 charactersBroken: practical collisions demonstrated
SHA-256256 bits64 charactersConsidered secure; the common choice today
SHA-384384 bits96 charactersConsidered secure
SHA-512512 bits128 charactersConsidered secure

The hex length is a handy way to tell which algorithm a published checksum uses: 64 characters almost always means SHA-256.

Why MD5 and SHA-1 are broken, and why they are still around

Researchers published practical MD5 collisions in 2004, and the technique has since been refined to the point where two different files with the same MD5 hash can be produced quickly on ordinary hardware. For SHA-1, a team from Google and CWI Amsterdam announced the first practical collision in 2017, producing two different PDF files with the same SHA-1 hash.

"Broken" here has a specific meaning. An attacker who controls both files can make them share a hash. That matters wherever someone could swap a harmless file for a malicious one with a matching fingerprint, as with digital signatures, certificates and security-sensitive downloads. Those uses have moved to the SHA-2 family.

It does not mean MD5 and SHA-1 have become useless. Random corruption, such as a download cut short or a failing disk, will not accidentally produce a collision. So both are still used to detect accidental damage, to deduplicate files, and in older systems. Git, for example, has long identified objects by SHA-1. The rule of thumb is simple: use MD5 or SHA-1 only when nobody is trying to fool you, and use SHA-256 or stronger whenever someone might be.

Step by step: verifying a download with Preslo

The Hash Generator has a File mode that calculates all five hashes at once and compares them with a checksum you paste in. The file is read and hashed inside your browser and is not uploaded.

  1. Get the checksum from the official source. Copy it from the publisher's own download page or release notes, not from a forum post or a mirror you do not trust.
  2. Download the file as usual and let it finish completely.
  3. Open the Hash Generator and choose File. Click the file picker and select the download. Files up to 512 MB are supported, because the whole file is read into memory first.
  4. Paste the published checksum into the Expected hash box. Upper and lower case do not matter, and stray spaces are ignored.
  5. Read the result. If the checksum matches, the matching algorithm is highlighted and you are told which one it is. If nothing matches, the file differs from the one the checksum describes.

If you get a mismatch, download the file again, ideally from the official site. A mismatch usually means a corrupted or incomplete download; less often, it means the file has been altered. Do not run it until the hashes match.

Command-line alternatives

For files larger than 512 MB, or if you prefer the terminal, every major operating system has a built-in command:

  • Windows (PowerShell): Get-FileHash filename -Algorithm SHA256
  • macOS: shasum -a 256 filename
  • Linux: sha256sum filename

What a matching checksum does and does not prove

A match proves that your file is byte-for-byte identical to the file the checksum was made from. It does not prove that file is safe. If an attacker took over a website and replaced both the download and the checksum on the same page, the two would still match. That is why it matters where the checksum comes from. Some projects also publish a digital signature, made with the developer's private key, which ties the file to its author more strongly than a checksum on the same page can. Verifying signatures needs separate tools and is outside what a hash generator does.

Why plain hashes are wrong for storing passwords

Because hashes are one-way, it can seem sensible to store a hash of each password instead of the password itself. Websites do store something derived from the password, but a plain, fast hash such as SHA-256 is the wrong choice, for two reasons.

  • Speed works for the attacker. General-purpose hashes are designed to be fast. If a database of hashes leaks, an attacker can test enormous numbers of guesses on their own hardware, and weak passwords fall quickly.
  • Identical passwords give identical hashes. Everyone who chose the same password has the same hash, and precomputed tables of common password hashes can be reused against any site.

Proper password storage uses a salt, a random value unique to each account mixed in before hashing, so identical passwords produce different stored values. It also uses an algorithm built to be deliberately slow and, in newer designs, memory-hungry: bcrypt, scrypt and Argon2 are the usual examples. These are tools for developers building login systems; the Preslo Hash Generator does not provide them. For your own accounts, what matters most is choosing long, unique passwords, which the guide to strong passwords covers in detail.

Common mistakes

  • Hidden characters in text. A trailing space or line break changes the hash completely. On the command line, echo adds a newline, so abc followed by a newline hashes to edeaaff3… rather than ba7816bf…. Use printf or echo -n instead.
  • Different text encodings. The same characters stored in a different encoding are different bytes. The Preslo tool hashes text as UTF-8, the standard almost everywhere today.
  • Comparing different algorithms. An MD5 value will never match a SHA-256 value. Check the length first.
  • Checking only the first few characters. Compare the whole value, or let the tool's comparison box do it.
  • Trusting a checksum from the same unofficial mirror as the file.
  • Treating a hash as encryption. Encryption can be reversed with a key; a hash cannot be reversed at all.

To spot where two pieces of text differ before you hash them, a text diff checker can help.

Key takeaways

  • A hash is a fixed-length fingerprint: the same input always gives the same output, and any change gives a different one.
  • MD5 and SHA-1 are fine for spotting accidental corruption but not where someone could tamper with data.
  • SHA-256 is the usual choice for download checksums today.
  • Always take the expected checksum from the official source, and re-download on a mismatch.
  • A matching hash proves the file is identical, not that it is trustworthy.
  • Passwords should be stored with salted, slow functions such as bcrypt, scrypt or Argon2, never a plain hash.

Frequently asked questions

Can a hash be reversed to get the original data?

No. Hash functions are one-way. Short or common inputs can sometimes be found by guessing many candidates and comparing hashes, but the hash itself cannot be decoded.

Is MD5 still safe to use?

Not where security matters, because collisions can be created deliberately. It is still acceptable for detecting accidental corruption or matching an older checksum.

How do I know which algorithm a checksum uses?

Count the hex characters: 32 usually means MD5, 40 means SHA-1, 64 means SHA-256, 96 means SHA-384 and 128 means SHA-512. Download pages usually label it too.

What should I do if a download's hash does not match?

Do not open or run the file. Download it again from the official source and check once more; if it still does not match, contact the publisher.

Why shouldn't websites store passwords as SHA-256 hashes?

Plain hashes are fast, so leaked hashes can be attacked with huge numbers of guesses, and identical passwords produce identical hashes. Password storage should use a unique salt with a slow algorithm such as bcrypt, scrypt or Argon2.

More guides

See all guides →