What SHA-256 is used for
SHA-256 is the 256-bit member of the SHA-2 family. It is the usual choice when you need a fingerprint that nobody can forge in practice. You meet it in several places:
- Download checksums published next to installers and disk images.
- TLS certificates, most of which are signed over a SHA-256 hash of their contents.
- Docker and container registries, where an image is identified by a digest like
sha256:followed by 64 hex characters. - Subresource Integrity, the
integrityattribute on script and link tags, which accepts SHA-256, SHA-384 and SHA-512. - Bitcoin, which uses double SHA-256 for block hashes and transaction identifiers.
Verifying a file with SHA-256
Hash the file on this page and compare the result with the checksum the publisher lists. If they match, every byte of your copy is identical to theirs. If they do not, download again, and if it still fails, do not run the file.
To confirm a result with another tool: sha256sum file on Linux, shasum -a 256 file on macOS, and Get-FileHash file -Algorithm SHA256 in Windows PowerShell. A checksum only helps if it comes from a trustworthy place: one stored on the same compromised server as the file proves nothing.
What SHA-256 does not do
SHA-256 is not a password hash. It is fast, so stolen hashes can be guessed at enormous speed. Use Argon2, scrypt or bcrypt with a salt for passwords.
It is also not a message authentication code. Prefixing a secret to a message and hashing it with plain SHA-256 is vulnerable to length extension, where an attacker appends data and computes a valid new hash. Use HMAC-SHA-256 for that job.
SHA-256 or SHA-512?
Both belong to SHA-2 and neither has a known practical attack. SHA-256 gives 64 hex characters and is what most tools and websites list. SHA-512 gives 128 and can be quicker on 64-bit processors for large inputs, while SHA-384 is a trimmed SHA-512 that is not exposed to length extension. If a publisher gives you one, check that one.