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.
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?
Why would a longer hash be faster?
What is SHA-512/256?
Which does TLS use?
Should I use either for passwords?
Tools used in this guide
All tools →- SHA-256 Hash Generator Generate a SHA-256 digest — the modern default. In your browser
- SHA-512 Hash Generator Generate a 512-bit SHA-2 digest. In your browser
- Hash Generator Generate MD5, SHA-1, SHA-256 and SHA-512 digests at once. In your browser
- HMAC Generator Sign a message with a secret key using HMAC. In your browser
Related guides
All guides →Last reviewed .