LHTSOFT Learn · Understand the why

How to verify a downloaded file with a SHA-256 checksum

A matching filename or file size cannot establish whether a download contains the expected bytes. A checksum gives you a practical way to compare the actual contents with a reference value obtained from a trusted source.

Published: · Updated:

Understand what SHA-256 measures

SHA-256 produces a 256-bit digest, normally written as 64 hexadecimal characters. It hashes bytes, not the filename or the appearance on screen. Two copies with identical bytes have identical digests; a mismatch proves the bytes differ, even if both files have the same size.

Obtain the expected value independently

Look for a SHA-256 digest on the publisher's official release page or a verified signed manifest. A digest supplied by the same untrusted mirror as the file cannot establish the publisher's identity. Save the expected value and confirm the exact release, platform and file variant before comparing.

Calculate and compare locally

On Windows PowerShell, run Get-FileHash -Algorithm SHA256 -LiteralPath './original.txt'. On GNU/Linux, use sha256sum original.txt; macOS normally provides shasum -a 256 original.txt. Compare all 64 characters, ignoring hexadecimal letter case. Check the path and algorithm if the result is unexpected.

Respond safely to a mismatch

Do not execute an installer with an unexplained mismatch. Verify the release version, download again from the official source, and compare the digest before opening it. A matching digest does not scan for malware or prove that the publisher's official file is safe; a signature and trusted distribution provide different assurances.

Reproduce a one-byte change

  1. Extract the original educational ZIP into an empty folder and keep original.txt, copy.txt and changed.txt unchanged.
  2. Inspect the sizes: each file is 26 bytes. Compute SHA-256 for original.txt and copy.txt using the command above.
  3. Compute the digest for changed.txt. Only one byte changes, from amount=100 to amount=101.
  4. Compare the complete values with the recorded manifest. Do not copy a digest from an unrelated file or compare only a few leading digits.

The original and copy have the same digest, 72973db85aa6be0203329e7e68769d47818984c5fe8f5de9bee7db594e570fef. The changed file has digest 3ffc0df2caae19a00454cafb32f2c6510f2e951b5cf5c356250404fd073b6aa7.

Independent laboratory results

Test date:

We created three 26-byte synthetic text files and verified their SHA-256 digests with Python hashlib, Node.js crypto and Windows PowerShell Get-FileHash. This is a local exercise, not a production tool export.

  • 26 B × 3
  • SHA-256(original.txt) = SHA-256(copy.txt)
  • SHA-256(original.txt) ≠ SHA-256(changed.txt)

Independent check: Python hashlib / Node.js crypto / Windows PowerShell Get-FileHash