A download finishes, you hash the file, you compare the result with the value on the download page, and they do not match. The instinct is to conclude the file is corrupt or tampered with. Very often, nothing is wrong with the file at all. The two values were produced by different algorithms, and a comparison across algorithms fails every single time, even for identical bytes.

This guide covers the two mistakes behind almost every false hash alarm: comparing values from different algorithms, and hashing slightly different bytes than you think you hashed. The rule that avoids both: same algorithm, same bytes, then compare. The examples use the free SHA Hash Generator on Ovatly, which computes all four SHA variants in your browser.

Contents

  • Quick answer
  • A hash only means something inside its own algorithm
  • Tell the algorithms apart by length
  • The second classic: the trailing newline
  • How to compare hashes properly, step by step
  • Worked example: one text, two algorithms
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

Never compare hash values produced by different algorithms. An SHA-1 hash of a file is 40 hex characters; an SHA-256 hash of the same file is 64, and the two will never match. Before comparing, count the characters of both values and confirm they belong to the same algorithm. Then confirm the bytes are really the same: for text, a trailing newline is the most common hidden difference. The SHA Hash Generator computes all four SHA variants on this device, so you can regenerate the value in the matching algorithm.

A hash only means something inside its own algorithm

A hash algorithm is a fixed recipe that turns any input into a fixed-length string of hex characters. SHA-1, SHA-256, SHA-384 and SHA-512 are four different recipes. Feed the identical file into two of them and you get two unrelated-looking strings, both correct, neither comparable.

Someone publishes a checksum in SHA-1, because the project is old and that is what it has always used. You compute SHA-256, because it is the right modern default. The values differ, the alarm sounds, and an hour goes into re-downloading and worrying over a file that was fine from the start.

The reverse mistake is quieter and worse: forcing a comparison to pass by truncating or eyeballing. A hash comparison is character by character and all or nothing. If the lengths differ, the comparison is already over, and no conclusion about the file exists yet.

Tell the algorithms apart by length

Each algorithm always produces the same output length, so length is a reliable identification label:

MD5:      32 hex characters
SHA-1:    40 hex characters
SHA-256:  64 hex characters
SHA-384:  96 hex characters
SHA-512:  128 hex characters

Before any comparison, count both values. If the counts differ, stop, identify each value's algorithm, then regenerate yours to match. This is also why checksum tools can auto-detect: a pasted value of 64 hex characters can only be SHA-256, and one of 32 can only be MD5.

Length also settles the SHA-1 question. SHA-1 collisions have been demonstrated in practice: two different files can be crafted to share an SHA-1 value. That is why SHA-1 is legacy only, kept for verifying old published checksums, and why SHA-256 is the default for anything new: no SHA-256 collision has ever been found in practice.

The second classic: the trailing newline

The other false alarm needs no second algorithm. You hash a short piece of text, the result disagrees with the expected value, and the text looks identical on screen. It is not identical. Text is hashed as UTF-8 exactly as typed, including the characters you cannot see.

The usual invisible difference is a trailing newline: the Enter pressed at the end of a line, or added when text is copied from a document or saved by an editor. One extra byte at the end is a different input, and a different input produces a completely different hash. This is, in practice, the most common cause of disagreement between two honestly computed SHA-256 values.

The lesson generalises: a hash compares bytes, not meanings or appearances. Two files that look and read the same can still hash differently because of one invisible byte, and the hash is right every time.

How to compare hashes properly, step by step

  1. Identify the algorithm of the reference value by counting its hex characters: 40 means SHA-1, 64 means SHA-256, 32 means MD5.
  2. Open the SHA Hash Generator and select that same algorithm. SHA-256 is the default for a new reference of your own.
  3. Choose Text or File and enter the input exactly. For text, allow no trailing newline unless the reference was computed with one. Files are read locally and never leave your device.
  4. Click Compute and compare the full digest against the reference, character by character, not just the first few characters.
  5. If the values differ, check the algorithm first, then the input for invisible bytes, before concluding anything about the file.

Worked example: one text, two algorithms

Take the short text abc, the worked example in the FIPS 180-4 standard itself. Run it through the generator with SHA-256 selected:

ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

That is 64 hex characters. Now switch the algorithm to SHA-1 and hash the same three letters. The result is a different string of 40 hex characters. The two share nothing meaningful, yet both are the correct hash of exactly the same input. Anyone comparing the SHA-1 value against the SHA-256 value above would report a mismatch and be wrong about the file.

Now the newline variant: hash abc followed by an Enter. The SHA-256 result changes completely, even though the text on screen still reads as abc. Same algorithm this time, but not the same bytes, so again no match, and again the hash is telling the truth.

Limitations and honest tradeoffs

A hash proves that bytes match a reference. It does not prove who published those bytes. If the reference value came from a compromised page, a matching hash happily confirms a bad file. Get reference values from the publisher's own site, over a secure connection.

Very large files are read fully into memory by the generator, which can be slow on a modest device. The computation is exact; the wait is the only cost.

Algorithm choice is also a real tradeoff. SHA-1 survives only because old checksums exist in that format. For a new reference you create today, SHA-256 is the right default; reaching for SHA-1 because it is shorter reintroduces a collision risk that has already been demonstrated.

Common mistakes

  • Comparing across algorithms. An SHA-1 reference against your SHA-256 result fails 100 percent of the time, on good files and bad alike. Match the algorithm first.
  • Comparing only the first few characters. Two values that start alike can still differ later. Compare the full digest.
  • Hashing text with a trailing newline. The invisible Enter is the most common reason an honest hash disagrees with a published one.
  • Assuming a mismatch means tampering. Most mismatches are wrong algorithm, wrong file or extra bytes. Work through those first.
  • Trusting a match as proof of a trustworthy source. A match proves identical bytes, never a trustworthy publisher.

FAQs

Can an SHA-1 hash and an SHA-256 hash of the same file ever match? No. They are outputs of different algorithms with different lengths: SHA-1 produces 40 hex characters and SHA-256 produces 64. A mismatch between two different algorithms says nothing at all about the file, only about the comparison.

How can I tell which algorithm a hash value belongs to? Count its characters. MD5 values are 32 hex characters, SHA-1 values are 40, SHA-256 values are 64, SHA-384 values are 96 and SHA-512 values are 128. Length is the quickest identification check there is.

My SHA-256 of a short piece of text does not match the published value. Why? The most common cause is a trailing newline. Text is hashed as UTF-8 exactly as typed, so text ending with an Enter key press is different input from the same text without it, and produces a completely different hash.

Does a matching hash prove who published the file? No. A match proves the bytes you have are identical to the bytes the reference hash was computed from. It says nothing about who published those bytes or whether that publisher was trustworthy.

Which SHA algorithm should I use by default? SHA-256. SHA-1 collisions have been demonstrated, so SHA-1 is kept only for verifying old published checksums that were issued in that format. No SHA-256 collision has ever been found in practice.

Conclusion

Almost every alarming hash mismatch is one of two boring mistakes: values from different algorithms placed side by side, or an invisible byte, usually a trailing newline, inside the input. Count the characters, match the algorithm, control the bytes, and the comparison becomes the reliable check it should be. When the question is not how a hash was produced but whether a file still matches a value you recorded earlier, our guide on checking whether a file changed since yesterday walks through that workflow. For more guides in this series, see our Security and Privacy guides.

References