How to Generate & Check a MD5 Checksum on Windows

Updated

md5 checksum windows

To generate an MD5 checksum on Windows 11 or Windows 10, open Command Prompt or PowerShell and run certutil with the path to the file:

certutil -hashfile "C:\Users\you\Downloads\file.iso" MD5

It displays the file’s MD5 checksum, 32 hexadecimal characters. If that matches the checksum the publisher lists, the file arrived intact. In PowerShell, Get-FileHash -Algorithm MD5 does the same job. One warning first: MD5 catches damaged downloads, but it can’t prove nobody tampered with a file. For that, change MD5 to SHA256.

Generate an MD5 checksum with certutil (Command Prompt)

Microsoft’s certutil reference lists Windows 11 and Windows 10 as supported and gives the syntax as:

certutil [options] -hashfile InFile [HashAlgorithm]

Put the path in double quotation marks if it contains spaces. I always type the algorithm: the reference doesn’t say which one certutil uses when you leave it out, and a checksum from the wrong algorithm will never match.

Generate an MD5 checksum with PowerShell (Get-FileHash)

Get-FileHash -Path 'C:\Users\you\Downloads\file.iso' -Algorithm MD5

Get-FileHash is a PowerShell command, so it works in PowerShell (the Windows PowerShell 5.1 that ships with Windows, or PowerShell 7) but not in Command Prompt. The output shows the algorithm, the hash and the path, and the hash is your checksum. Without -Algorithm you get SHA256, which is 64 characters and can never equal an MD5 value. If a file name contains square brackets, use -LiteralPath instead of -Path, which reads them as wildcards.

Compare the checksum with the published value

Don’t compare 32 characters by eye. Get-FileHash prints capital letters, a publisher may use either case, and one wrong character is easy to miss. Let PowerShell make an exact, case-insensitive comparison:

(Get-FileHash -Path 'C:\Users\you\Downloads\file.iso' -Algorithm MD5).Hash -ieq 'PASTE_THE_PUBLISHED_MD5_HERE'

It prints True or False. -ieq is the explicitly case-insensitive form of -eq, so capitals and lowercase count as the same. Nothing else is forgiven: a stray space, a missing character or a checksum from a different algorithm gives False.

If you made the checksum with certutil, paste both strings into PowerShell and compare them directly:

'PASTE_THE_CERTUTIL_OUTPUT_HERE' -ieq 'PASTE_THE_PUBLISHED_MD5_HERE'

Match the algorithm to the published checksum

Publishers don’t always label their checksums, but the length usually identifies the algorithm:

Length of the published value Algorithm certutil Get-FileHash -Algorithm
32 characters MD5 MD5 MD5
40 characters SHA-1 SHA1 SHA1
64 characters SHA-256 SHA256 SHA256 (the default)
96 characters SHA-384 SHA384 SHA384
128 characters SHA-512 SHA512 SHA512

If the lengths differ, you used a different algorithm from the publisher, or part of the value was lost when you copied it. If they match but the values don’t, you don’t have the file the publisher hashed, so download it again from the publisher’s own site. Rarer algorithms such as SHA-512/256 also produce 64 characters, so trust the publisher’s label when there is one.

Check every file in a folder

certutil’s syntax takes a single input file, so use PowerShell for a folder. This hashes every file in the folder and its subfolders (-Force includes hidden and system files; drop -Recurse to skip subfolders):

Get-ChildItem -LiteralPath 'C:\Users\you\Downloads\myfolder' -Recurse -File -Force | Get-FileHash -Algorithm MD5

I use -LiteralPath because Microsoft recommends it over -Path when you add -Recurse. To save the list as a CSV file, pipe it to Export-Csv. -NoTypeInformation drops a #TYPE line that Windows PowerShell 5.1 would otherwise add, and -Encoding UTF8 keeps accented and non-Latin file names intact, because 5.1 writes ASCII by default:

Get-ChildItem -LiteralPath 'C:\Users\you\Downloads\myfolder' -Recurse -File -Force |
    Get-FileHash -Algorithm MD5 |
    Export-Csv -Path 'C:\Users\you\md5-hashes.csv' -NoTypeInformation -Encoding UTF8

To check that a copy matches the original, hash both folders and compare the results:

$a = Get-ChildItem -LiteralPath 'C:\Photos' -Recurse -File -Force | Get-FileHash -Algorithm MD5
$b = Get-ChildItem -LiteralPath 'E:\Photos backup' -Recurse -File -Force | Get-FileHash -Algorithm MD5
Compare-Object $a $b -Property Hash -PassThru | Select-Object -Property SideIndicator, Hash, Path

No output means both folders hold the same file contents. A <= row is a hash found only in the first folder and a => row one found only in the second, so a damaged copy shows up as a pair: the original under <=, the changed copy under =>. It compares contents, not names, so a renamed or moved file isn’t flagged. Select-Object is there because -PassThru hides the SideIndicator column by default.

When MD5 is enough and when to use SHA-256

A matching MD5 is good evidence that a file wasn’t damaged in transit or on disk. Microsoft’s Get-FileHash documentation says MD5 and SHA1 “should only be used for simple change validation”, not for files that need protection from attack or tampering. The IETF’s RFC 6151 likewise calls an MD5 checksum used solely to protect against errors an acceptable use.

Deliberate tampering is the problem. A collision is two different inputs with the same checksum, and NIST expects an approved hash function to make those infeasible to find. MD5 doesn’t: RFC 6151 says it is “no longer acceptable where collision resistance is required” and cites research that finds MD5 collisions in about a minute on a notebook PC, and later work in ten seconds or less. I don’t treat a matching MD5 as proof that a file hasn’t been altered.

SHA-256 is the usual replacement. It is one of the algorithms in NIST’s approved list (FIPS 180-4), which doesn’t include MD5, and Microsoft’s cryptographic recommendations tell developers to use the SHA-2 family: SHA-256, SHA-384 and SHA-512. SHA-1 is no substitute: Microsoft groups it with MD5, and NIST deprecated it in 2011. So when a publisher lists both, I check the SHA-256 value, which only means changing the last word:

certutil -hashfile "C:\Users\you\Downloads\file.iso" SHA256

Get-FileHash -Path 'C:\Users\you\Downloads\file.iso'

The second command needs no -Algorithm because SHA256 is the default. Even SHA-256 only proves the file matches whatever the checksum came from: if someone can replace a download, they may be able to replace the checksum on the same page. I’d take the checksum from the publisher’s own HTTPS site, and check a digital signature as well when one is offered. MD5 is still fine when nobody is attacking anything: spotting a damaged download, checking a copy to a USB drive, comparing two of your own folders.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.