Comparison

SHA-256 vs SHA-512

SHA-256 and SHA-512 are both members of the SHA-2 family and both are secure, with no practical attacks against either. SHA-512 produces a longer digest and often runs faster on 64-bit hardware because it operates on 64-bit words. SHA-256 produces shorter values and is more widely expected by other systems. For most work, choose SHA-256 for compatibility.

SHA-256 Hash Generator

Generate a SHA-256 digest — the modern default.

Open the tool

This is not a security decision. Both are unbroken, and the extra digest length of SHA-512 provides margin far beyond anything current or foreseeable computing can threaten. Choosing between them is about performance characteristics and what the systems you talk to expect.

The counter-intuitive part is speed. SHA-512 is often faster than SHA-256 on 64-bit processors despite producing twice the digest, because it works on 64-bit words natively. On 32-bit hardware that advantage reverses.

Practical differences

  • Digest: SHA-256 is 64 hex characters, SHA-512 is 128.
  • Word size: SHA-256 uses 32-bit words, SHA-512 uses 64-bit.
  • Speed: SHA-512 is often faster on 64-bit CPUs, slower on 32-bit and small embedded devices.
  • Hardware acceleration: many CPUs include SHA-256 instructions but not SHA-512, which can reverse the comparison.
  • Ubiquity: SHA-256 is the more commonly expected default.

Length extension

Both are vulnerable to length-extension attacks: given H(secret + message) and the message length, an attacker can compute H(secret + message + extra) without knowing the secret. This is why you should never authenticate a message by hashing a secret and the message together. Use HMAC, which is built to resist exactly this. SHA-512/256 — SHA-512 truncated to 256 bits — is also immune, but it is much less widely supported.

Which to choose

Default to SHA-256 unless you have a reason not to. It is what other systems expect, its values are shorter to store and transmit, and hardware acceleration for it is common. Choose SHA-512 when a standard you are implementing requires it, or when you have benchmarked it faster on your specific 64-bit hardware and are hashing enough data for that to matter.

Frequently asked questions

Is SHA-512 twice as secure as SHA-256?
It has twice the digest length, but both are far beyond any practical attack. SHA-256 offers roughly 128 bits of collision resistance, which is not going to be brute-forced. The extra length is margin, not a meaningful difference in practice.
Why would a longer hash be faster?
SHA-512 operates on 64-bit words, so a 64-bit processor does more work per instruction. That can outweigh the larger digest. On 32-bit or embedded hardware the advantage disappears, and CPUs with SHA-256 hardware instructions can make SHA-256 faster again.
What is SHA-512/256?
SHA-512 computed with different initial values and truncated to 256 bits. It gets SHA-512's 64-bit performance with a short digest, and truncation makes it immune to length-extension attacks. Support is limited, which is why it is uncommon.
Which does TLS use?
Mostly SHA-256, which is by far the more common choice in certificates and cipher suites. SHA-384 also appears in some suites. SHA-512 is comparatively rare in TLS.
Should I use either for passwords?
No. Both are general-purpose hashes designed to be fast, which is the opposite of what password storage needs. Use bcrypt, scrypt or Argon2, which are deliberately slow and salt each hash.

Tools used in this guide

All tools →
All guides →

Last reviewed .