gizmobench
BrowseDaily
← All guides

GizmoBench guides

Hash Functions Explained: SHA-256, MD5 and File Checksums

GizmoBench ·

A hash function takes input of any length and returns a fixed-length value, often called a digest or hash. The same input always gives the same output, and changing the input even slightly gives a completely different one. That property is why hashes work as fingerprints for files, passwords and messages, and why you can use one to check that a download arrived intact.

This guide covers what a hash function does, what SHA-256 is, how it compares with MD5, and how to verify a file checksum on your own computer, including what a match does and does not prove. If you work with hashes and encodings often, the browser-based developer tools at GizmoBench run locally, with no account and no upload.

GizmoBench
Work With Hashes in Your Browser
GizmoBench offers browser-based developer tools that run locally, with no account or software installation needed.

TL;DR

  • A hash function maps input of any size to a fixed-size output; the same input always produces the same digest, and a tiny change produces an entirely different one.
  • SHA-256 is a NIST-specified algorithm with a 256-bit digest, and it is the safer default for new checksums. MD5 is not collision-resistant and should not be used where someone might tamper with the file.
  • To verify a download, compute its SHA-256 in a terminal, then compare the complete value with the one the publisher lists.
  • A matching checksum shows the file is unchanged since the checksum was computed. It does not prove the publisher is genuine, because an attacker who replaces the file could replace the checksum too.

Table of Contents

What a hash function does

The MDN glossary describes a hash function as one that takes a variable-length input and produces a fixed-length output, called the digest or hash. It should be quick to compute, and different inputs should, as far as possible, produce different outputs. NIST phrases it the same way: a hash algorithm maps a message of arbitrary length to a fixed-length message digest.

Two consequences follow from that definition, and both matter in practice.

  1. The output size does not depend on the input size. A one-word text file and a multi-gigabyte disk image both produce a SHA-256 digest of 256 bits, which is conventionally written as 64 hexadecimal characters.
  2. The mapping goes one way. You can compute the digest from the file, but you cannot reasonably rebuild the file from the digest. A digest is a fingerprint, not a compressed copy.

The avalanche behavior is easy to see. Microsoft’s security documentation notes that changing a single letter, such as “microsoft” versus “Microsoft”, changes the SHA-256 hash entirely. There is no “close” hash for a close input, so a mismatch tells you only that something differs, never how much.

Two families of hash function

The phrase covers two quite different jobs, and search results for this topic often mix them.

  • Data-structure hashing is used in hash tables, where a hash decides which slot stores a value so lookups are fast. Occasional collisions (two inputs landing in the same slot) are handled by the table, and nobody is trying to forge them.
  • Cryptographic hashing is used for integrity and security, where someone may deliberately try to craft a collision. This is the family SHA-256 and MD5 belong to, and it is what the rest of this article covers.

The properties that make a hash cryptographic

MDN lists three requirements on top of speed. A cryptographic hash must be one-way (impractical to recover the input from the output), tamper-resistant (any change to the input changes the output), and collision-resistant (impractical to find two different inputs with the same output).

NIST states these as three formal properties of an approved hash function:

Property Plain meaning SHA-256 strength (NIST)
Collision resistance Hard to find any two inputs with the same digest 128 bits
Preimage resistance Given a digest, hard to find an input that produces it 256 bits
Second preimage resistance Given one input, hard to find a different input with the same digest 256 bits minus a term that depends on message length

The gap between 128 and 256 bits is not a flaw. NIST SP 800-107 explains that for an L-bit hash the expected collision resistance is L/2 bits, while preimage resistance is L bits. The same document gives a useful warning about shortening digests: truncating to 96 bits leaves only 48 bits of collision resistance. If you compare only the first few characters of a hash, you are doing a weaker check than the algorithm was built for.

What is SHA-256?

SHA-256 is one member of the SHA-2 family. NIST’s glossary defines it as a hash algorithm from FIPS 180-4 that generates message digests used to detect whether messages have changed since the digests were generated. The standard, FIPS 180-4 (August 2015), says SHA-256 processes the message in 512-bit blocks and outputs a 256-bit digest, and that any change to a message will, with very high probability, produce a different digest.

NIST’s approved list also includes SHA-224, SHA-384, SHA-512 and two truncated SHA-512 variants in FIPS 180-4, plus the SHA-3 family in FIPS 202. For everyday file checking, SHA-256 is the value most publishers list next to a download.

You will see SHA-256 in several places:

  • Download pages that list a checksum beside an installer or disk image.
  • Package managers and software registries, which use hashes to confirm that what you downloaded matches what the server holds. PyPI’s documentation describes this as verifying that the downloaded file matches the one on its servers.
  • Security protocols and digital signatures, where a hash of the message is what actually gets signed.
  • Blockchains, where Bitcoin applies SHA-256 twice for block hashes and transaction IDs, according to one glossary.

MD5 vs SHA-256: which should you use?

MD5 is older, shorter (128 bits, 32 hex characters) and faster. Its speed made it the default for years, and many download pages still list MD5 values. The question is not whether MD5 “works” but what threat you are guarding against.

CodePath’s checksum guide explains that practical MD5 collisions were demonstrated in 2004 and SHA-1 collisions in 2017 (the SHAttered attack). A collision means an attacker can build two different files with the same hash, which defeats the purpose of a tamper check. The same guide says a simple checksum such as CRC32 is enough to catch accidental corruption, while SHA-256 is recommended where deliberate tampering must be detected.

The Digital Preservation Coalition’s December 2020 guidance note by Matthew Addis puts the trade-off clearly: MD5 is perfectly suitable for detecting accidental corruption in storage or transit, but strong cryptographic hashes such as SHA-256 or SHA-512 are needed when checksums must resist malicious tampering, at the cost of more computation.

Situation Reasonable choice
Checking that a copy of your own photos was not damaged in transfer MD5 or SHA-256 both detect accidental corruption
Verifying an installer or disk image from the internet SHA-256
Building a new checksum list for an archive or backup SHA-256
Anything where an attacker could benefit from swapping the file SHA-256 or stronger, never MD5 or SHA-1

The practical rule: use SHA-256 for anything new, and treat MD5 as acceptable only for catching accidental damage when that is all a publisher offers. On SHA-1, NIST’s hash policy page says that after December 31, 2030, FIPS 140 validated modules with SHA-1 as an approved algorithm move to the historical list, and federal agencies should use SHA-2 or SHA-3. In 2015 NIST encouraged SHA-256 at a minimum for interoperable applications.

How to verify a file checksum

A checksum is a small value generated by running a cryptographic hash function over a file. The LCSB data-integrity how-to describes the logic: as long as the file does not change, recalculating gives the same value, and a different value means the file was altered or corrupted. The process has four steps.

Four steps for verifying a file checksum

Step 1: Find the published checksum

Look on the publisher’s download page for a SHA-256 value, or a file named something like SHA256SUMS. Copy it from the publisher’s own HTTPS page, not from a forum post or a mirror. The value is only as trustworthy as the place you got it from.

Step 2: Compute the checksum of your download

Use the tool built into your operating system, from the folder containing the file:

  • Windows (PowerShell): Get-FileHash .\yourfile.iso -Algorithm SHA256
  • macOS (Terminal): shasum -a 256 yourfile.iso
  • Linux (terminal): sha256sum yourfile.iso

Large files take a while, since the whole file is read. Nothing is uploaded anywhere when you run these commands.

Step 3: Compare the complete value

Hexadecimal case does not matter. One practical guide points out that PowerShell prints uppercase while websites commonly use lowercase, and that the values are still equal. The same guide warns against checking only the first and last few characters and assuming the middle matches. Given the truncation point above, a partial comparison is a weaker test than the full 64 characters.

Step 3: Compare the complete value

When the publisher gives you a checksum list, let the tool do the comparing. On Linux, sha256sum -c checks each file against the list, reports OK or FAILED per file, and returns a nonzero exit status on failure. That removes the human error of reading 64 characters by eye.

Step 4: Act on the result

  • Match: the file is the same as the one the checksum was computed from.
  • Mismatch: do not open or install the file. Delete it and download it again, ideally on a stable connection. If the mismatch repeats, the file on the server may have changed or the published value may be out of date, so check the publisher’s page for notes.

A worked example

Suppose a project publishes this line beside its installer:

SHA256SUMS: 3f7a…(64 hex characters)… installer.zip

You download installer.zip, run sha256sum installer.zip, and get a 64-character value. If every character agrees with the published one, the download is bit-for-bit the file that was checksummed. If one character differs, the whole digest looks unrelated, which is the avalanche effect at work. Even a single flipped bit during transfer would show up this way.

What a matching checksum does and does not prove

A match tells you the file has not changed since the checksum was computed. That is a narrower claim than “this file is safe”, and it helps to be precise about the limits.

  • It does not prove who published the file. PyPI’s documentation notes that verification requires trusting the source of the checksum and the HTTPS channel it travels over. If both the file and its checksum come from a compromised page, the check still passes. Stéphane Robert’s guide makes the same point and describes GPG signatures, checked with a key obtained through an independent channel, as the way to get a real authenticity guarantee.
  • It does not tell you what changed. The Digital Preservation Coalition note says checksums do not reveal what changed, when, by whom, or how to repair the damage. They are an alarm, not a diagnosis.
  • It depends on the algorithm. A match on a truncated or weak hash is weaker evidence than a match on a full SHA-256 value.

For most downloads, a full SHA-256 comparison against a value from the publisher’s HTTPS page is the right level of effort. For software where the publisher offers a signed checksum file, verifying the signature first and then the checksums is the stronger route.

Where else you meet hashes

Passwords

Websites should store a hash of your password rather than the password itself. General-purpose hashes such as SHA-256 are built to be fast, which MDN lists as a desirable property for hash functions in general, but speed is not what you want when defending passwords against guessing. Dedicated password-hashing schemes such as bcrypt exist for that. If you build or test login systems, the bcrypt generator hashes and verifies in your browser, and the bcrypt password checker handles $2a$, $2b$ and $2y$ hashes.

Identifying an unknown hash

If you have a string of hex characters and no label, the length is a first clue: 32 characters suggests a 128-bit digest such as MD5, and 64 suggests a 256-bit one such as SHA-256. The hash identifier helps you work out what kind of hash a string is.

Records and timestamps

Hashes are also used to show that a record has not been edited after the fact. A hash of a job report, stored alongside a trusted timestamp, lets anyone later recompute the hash and see whether the document still matches. This article on tamperproof timestamps and what they prove walks through that idea for job records, including its limits.

Encodings are not hashes

Base64 and similar encodings are often confused with hashing. Encoding is reversible by design: anyone can decode it, and no key or secret is involved. A hash is meant to be one-way. If you need to decode a Base64 string, the Base64 decode guide shows how for text, images and files. Likewise, a JSON Web Token can be read in the browser because its parts are encoded, with the signature being the cryptographic piece.

Doing this work in your browser

GizmoBench is a collection of browser-based tools, and the developer set includes a JSON formatter and a Base64 encoder and decoder, alongside the hash identifier and bcrypt tools linked above. The tools run locally in the browser with no account or installation, and file processing happens on your device rather than on a server. That matters for hash work, where the inputs are often files or strings you would rather not send anywhere. Core tool functions are free to use without an account.

FAQ

Is SHA-256 the same as encryption?

No. Encryption is designed to be reversed by someone holding the key. A hash is one-way and has no key: you cannot recover the original input from a SHA-256 digest. Hashing is used to detect changes and to fingerprint data, not to hide it.

Can two different files have the same SHA-256 hash?

In theory yes, because infinitely many inputs map to a fixed number of outputs. In practice NIST rates SHA-256 at 128 bits of collision resistance, meaning finding such a pair is computationally impractical. That is the difference from MD5 and SHA-1, where practical collisions have been demonstrated.

Is MD5 still fine for checking a download?

It detects accidental corruption well enough, which the Digital Preservation Coalition describes as a suitable use. It does not protect against someone deliberately swapping the file, so for software downloads and anything security-sensitive, compare a SHA-256 value instead.

Does a matching checksum mean the file is safe?

It means the file matches the one the checksum was computed from. If the checksum came from the publisher’s own HTTPS page, a match is good evidence the download was not damaged or altered in transit. It does not by itself prove the publisher is trustworthy, which is what signatures are for.

Why does my hash use uppercase letters while the website shows lowercase?

Hexadecimal digits are case-insensitive. PowerShell prints uppercase, and many sites print lowercase, but the values are equal. Compare all 64 characters, or let a tool such as sha256sum -c do it.

Sources