Short answer: every desktop OS can hash a file without installing anything. On Windows run Get-FileHash file.iso in PowerShell; on macOS run shasum -a 256 file.iso; on Linux run sha256sum file.iso. Compare the result with the checksum the publisher lists, or look it up in NIST NSRL to see whether the file is known software.

Commands at a glance

A file hash (or checksum) is a fixed-length fingerprint of a file’s exact bytes. Change one byte and the hash changes completely, so two files with the same SHA-256 are, for practical purposes, the same file. The three you will meet most are MD5 (32 hex characters), SHA-1 (40) and SHA-256 (64).

SystemSHA-256SHA-1MD5
Windows (PowerShell)Get-FileHash fGet-FileHash f -Algorithm SHA1Get-FileHash f -Algorithm MD5
Windows (Command Prompt)certutil -hashfile f SHA256certutil -hashfile f SHA1certutil -hashfile f MD5
macOSshasum -a 256 fshasum -a 1 fmd5 f
Linuxsha256sum fsha1sum fmd5sum f

Windows: Get-FileHash and certutil

PowerShell: Get-FileHash

Open PowerShell (Start → type PowerShell) and point Get-FileHash at the file. It uses SHA-256 unless you say otherwise:

PowerShellGet-FileHash C:\Users\you\Downloads\empty.txt Algorithm Hash Path --------- ---- ---- SHA256 E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 C:\Users\you\Downloads\empty.txt

(That is the real SHA-256 of an empty, zero-byte file, a handy value to recognise.) For MD5 or SHA-1, add -Algorithm. To print only the hash, wrap the command and take .Hash:

PowerShellGet-FileHash .\setup.exe -Algorithm MD5 (Get-FileHash .\setup.exe -Algorithm SHA1).Hash

Get-FileHash can also hash folders, export CSVs and compare files. The Get-FileHash guide has examples for all of these.

Command Prompt: certutil

certutil is older but works in any Command Prompt, including on machines where PowerShell is restricted. Name the algorithm explicitly, because certutil defaults to SHA-1:

cmdcertutil -hashfile C:\Users\you\Downloads\setup.exe SHA256

It prints a header line (“SHA256 hash of …”), the hash in lowercase, and “CertUtil: -hashfile command completed successfully.” Supported algorithms are MD2, MD4, MD5, SHA1, SHA256, SHA384 and SHA512.

Gotcha: certutil refuses zero-byte files (it reports ERROR_FILE_INVALID). Get-FileHash handles them fine.

macOS: shasum and md5

Open Terminal and use shasum with -a for the algorithm (the default is SHA-1, so pass -a 256 for SHA-256). For MD5 there is a separate md5 command:

Terminalshasum -a 256 ~/Downloads/empty.txt e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 /Users/you/Downloads/empty.txt md5 ~/Downloads/empty.txt MD5 (/Users/you/Downloads/empty.txt) = d41d8cd98f00b204e9800998ecf8427e md5 -q ~/Downloads/empty.txt # hash only d41d8cd98f00b204e9800998ecf8427e

Tip: type the command and a space, then drag the file from Finder into the Terminal window to paste its path.

Linux: sha256sum and md5sum

Linux ships one command per algorithm in GNU coreutils: sha256sum, sha1sum, md5sum (and sha512sum). The output is the hash, two spaces, then the file name:

bashsha256sum ubuntu.iso md5sum ubuntu.iso sha1sum ubuntu.iso

You can pass several files, or a wildcard such as sha256sum *.iso, and get one line per file.

Any OS: Python

If you need the same script on every platform, Python’s standard hashlib module does it. Read the file in chunks so large disk images don’t fill memory:

Pythonimport hashlib def file_hash(path, algorithm="sha256"): h = hashlib.new(algorithm) # "md5", "sha1", "sha256", ... with open(path, "rb") as f: for chunk in iter(lambda: f.read(1024 * 1024), b""): h.update(chunk) return h.hexdigest() print(file_hash("ubuntu.iso"))

On Python 3.11 and later, hashlib.file_digest(f, "sha256").hexdigest() does the chunked read for you.

Verify a checksum

When a vendor publishes a checksum next to a download, verifying it proves you received exactly the file they published: not truncated, not corrupted, not swapped. Hash the file with the same algorithm they used, then compare.

Windows (PowerShell): -eq ignores case, so uppercase and lowercase hex compare correctly:

PowerShell(Get-FileHash .\setup.exe).Hash -eq "paste-the-published-sha256-here" True

Linux and macOS: feed the expected hash and file name to the -c (check) option. Note the two spaces between hash and file name:

bashecho "paste-the-published-sha256-here ubuntu.iso" | sha256sum -c ubuntu.iso: OK # macOS echo "paste-the-published-sha256-here ubuntu.iso" | shasum -a 256 -c # or check every file listed in a vendor's SHA256SUMS file sha256sum -c SHA256SUMS --ignore-missing

If the hashes differ, check that you used the right algorithm (count the characters: 32, 40 or 64) and the right file version before assuming the worst. A mismatch with the correct algorithm means the file is not the one that was published, so download it again from the official source.

Hash every file in a folder

For an investigation, an audit or a software inventory you usually need a hash for every file in a folder tree, not just one. Each command below writes the hashes to a file you can keep, and a hashes.txt with one hash per line that you can look up in bulk.

Windows (PowerShell)

PowerShellGet-ChildItem -Path C:\Evidence -Recurse -File | Get-FileHash -Algorithm SHA256 | Export-Csv -Path hashes.csv -NoTypeInformation # one unique hash per line, for bulk lookups Import-Csv hashes.csv | Select-Object -ExpandProperty Hash | Sort-Object -Unique | Set-Content hashes.txt

Linux

bashfind /mnt/evidence -type f -exec sha256sum {} + > hashes.sha256 # one unique hash per line (sha256sum prefixes a "\" when a file name contains a backslash or newline) cut -d' ' -f1 hashes.sha256 | tr -d '\\' | sort -u > hashes.txt

macOS

Terminalfind ~/Evidence -type f -exec shasum -a 256 {} + > hashes.sha256 cut -d' ' -f1 hashes.sha256 | sort -u > hashes.txt

Write the output outside the folder you are hashing. Run these from a different directory, or give the output a full path elsewhere. Otherwise the half-written hash list gets hashed too.

Removing duplicates (sort -u, Sort-Object -Unique) matters on real systems: thousands of files share the same contents, and you only need to look each hash up once.

Look the hashes up in NIST NSRL

A list of hashes becomes useful when you can tell which files you already know about. The NIST National Software Reference Library (NSRL) catalogs the hashes of more than 1.5 billion files from published software: operating systems, applications, drivers and libraries. If a hash is in NSRL, the file is known, so you can set it aside and spend your time on the files that aren’t.

  • A few hashes: paste up to 10 into the lookup on the home page. No account is needed.
  • A whole folder: use the free API or the hashscanner command-line tool with the hashes.txt from the previous step:
bashpip install hashscanner export HASHSCANNER_API_KEY="hs_xxxx_sk_xxxx" # PowerShell: $env:HASHSCANNER_API_KEY = "hs_..." hashscanner bulk hashes.txt --format csv -o results.csv

Each row of results.csv says whether the hash was found and, when it was, the file name, size, product and operating system NSRL recorded for it. A free account covers 2,500 lookups a month and 100 hashes per bulk job; paid plans go up to 100,000 hashes per job (see pricing).

Known isn’t the same as safe. NSRL tells you a file has been cataloged as part of published software. It does not say the file is good or bad. Use a match to filter the known files out, then focus your review on the unknown ones.

FAQ

Does Windows have a built-in file hash checker?

Yes, two. PowerShell’s Get-FileHash (SHA-256 by default; also SHA-1, SHA-384, SHA-512 and MD5) and the older certutil -hashfile command, which works in Command Prompt. Neither needs anything installed.

Which hash should I use: MD5, SHA-1 or SHA-256?

Use whatever the publisher lists when you are verifying a download, since you have to compare like with like. For your own records use SHA-256: MD5 and SHA-1 have practical collision attacks. All three are still useful for identifying files, which is why NIST NSRL publishes them side by side.

Why doesn’t my hash match the published checksum?

Usually it is a different algorithm (an MD5 is 32 characters, SHA-1 40, SHA-256 64), a different file or version than the one the checksum was published for, or an incomplete or corrupted download. Upper and lower case don’t matter: hex hashes are case-insensitive.

Is checking a file hash the same as scanning it for malware?

No. A hash identifies the exact bytes of a file. Comparing it with a vendor checksum proves you have the file they published; looking it up in NIST NSRL tells you whether the file is known (cataloged software). Neither is a verdict that the file is safe or malicious.

Does looking up a hash upload my file?

Not with HashScanner. You compute the hash on your own machine and send only the hash string, so the file itself never leaves your system.

Got a list of hashes? Look them up in NIST NSRL

Paste up to 10 on the home page, no account needed. Free accounts get 2,500 lookups a month by API.