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).
| System | SHA-256 | SHA-1 | MD5 |
|---|---|---|---|
| Windows (PowerShell) | Get-FileHash f | Get-FileHash f -Algorithm SHA1 | Get-FileHash f -Algorithm MD5 |
| Windows (Command Prompt) | certutil -hashfile f SHA256 | certutil -hashfile f SHA1 | certutil -hashfile f MD5 |
| macOS | shasum -a 256 f | shasum -a 1 f | md5 f |
| Linux | sha256sum f | sha1sum f | md5sum 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:
(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:
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:
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:
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:
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:
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:
Linux and macOS: feed the expected hash and file name to the -c (check) option. Note the two spaces between hash and file name:
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)
Linux
macOS
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
hashscannercommand-line tool with thehashes.txtfrom the previous step:
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.