SHA-1 vs SHA-256 vs SHA-512: which hash should you use?

Choosing a hash algorithm is mostly about knowing which property you need. This guide compares the four SHA variants available through the browser Web Crypto API, shows their exact output lengths, and explains why none of them should hash a password.

Output length at a glance

AlgorithmDigest sizeHex charactersPractical status
SHA-1160 bits40Legacy compatibility only; collisions demonstrated
SHA-256256 bits64General-purpose default
SHA-384384 bits96Conservative choice for long-lived records
SHA-512512 bits128Maximum digest length of the SHA-2 family here

All four outputs are lowercase hexadecimal. The same input always produces the same digest: hashing is deterministic, not encryption, and there is no key to reverse the operation.

Which one should you use

For a checksum that confirms a text payload was not altered, use SHA-256. For a system that insists on SHA-1, keep it strictly for compatibility and never treat the result as a security guarantee. For records that must stay meaningful for many years, SHA-384 or SHA-512 buys additional collision margin at no meaningful cost for small inputs.

The practical conclusion: SHA-256 is the right default for nearly all everyday verification. The longer variants add resistance you rarely need rather than fixing a weakness in SHA-256.

The password mistake

SHA algorithms are designed to be fast, which is exactly the wrong property for passwords. A single SHA-256 operation takes microseconds on commodity hardware, so an attacker with a stolen digest can test billions of candidate passwords per second. Use a deliberately slow, salted function such as Argon2, bcrypt or scrypt instead. A 20-character random password generated with a cryptographically secure source is a far stronger control than the choice of digest.

Hashing a file is not the same as hashing text

A text tool hashes the UTF-8 bytes of a JavaScript string. A file hash reads the raw bytes on disk. Changing line endings, adding a byte-order mark or interpreting the same characters in a different encoding changes the digest completely. When you verify a downloaded file, use a tool that reads the file itself rather than pasting its contents into a text field.

A practical checksum workflow

  1. Generate the digest of the payload you want to protect.
  2. Publish or receive the expected digest through a separate channel from the payload itself.
  3. Recompute the digest at the receiving end and compare the strings character for character.

A match proves the bytes are identical. It does not prove who produced them, and it does not protect against an attacker who can modify both the payload and the published digest.

Frequently asked questions

Which SHA algorithm should I use by default?

SHA-256. It is supported everywhere, produces a 64-character hexadecimal digest and has no practical collision concerns for ordinary verification work.

Is SHA-1 still safe?

No. Chosen-prefix collisions have been demonstrated. Keep SHA-1 only for legacy systems that require it, never for signatures, certificates or integrity decisions.

Are longer hashes always better?

Not necessarily. SHA-384 and SHA-512 provide more collision resistance, but SHA-256 is already sufficient for almost all everyday checks. On 32-bit devices SHA-512 can be slower, not faster.

Can I use these hashes for passwords?

No. General-purpose hashes are far too fast. Use Argon2, bcrypt or scrypt with a unique salt per password.

Use the Hash Generator →

Page last reviewed: