What Is a Cryptographic Hash Function?
A cryptographic hash function takes an input of arbitrary length and produces a fixed-length output called a digest. The same input always produces the same digest, but a different input produces a completely different one. From the digest alone, it is computationally infeasible to reconstruct the input.
The SHA family (Secure Hash Algorithm) was designed by the US National Security Agency and published by NIST. SHA-256 is part of the SHA-2 family, first published in 2001.
SHA-256 at a Glance
- Output: 256 bits, rendered as 64 hexadecimal characters
- Block size: 512 bits (64 bytes)
- Algorithm: Merkle–Damgård construction with Davies–Meyer compression
The algorithm processes the input in 512-bit chunks. Each chunk goes through 64 rounds of a compression function that mixes the data using bitwise operations, modular addition, and a set of constants derived from the fractional parts of the cube roots of the first 64 prime numbers.
The Four Properties That Make It Useful
Pre-image resistance. Given a hash h, it is infeasible to find any m such that hash(m) = h. This is what makes hashes safe to publish — knowing the hash does not reveal the original input.
Second pre-image resistance. Given an input m1, it is infeasible to find a different m2 such that hash(m1) = hash(m2).
Collision resistance. It is infeasible to find any two distinct inputs that produce the same hash. SHA-256 has never had a known collision.
Avalanche effect. Changing a single bit of the input changes roughly half of the output bits. "Hello" and "hello" produce completely different hashes.
Common Applications
File integrity. Download pages publish SHA-256 checksums so users can verify a downloaded file is exactly what the server sent and has not been tampered with.
Digital signatures. Code signing and document signing hash the content first, then sign the hash. This is faster than signing the entire document and produces the same guarantee.
TLS certificates. Every HTTPS certificate uses SHA-256 to sign a hash of the certificate data. When your browser establishes a TLS connection, it verifies this signature.
Password hashing (not recommended alone). SHA-256 should not be used directly for passwords because it is too fast — attackers can compute billions of guesses per second. Use bcrypt, Argon2, or scrypt instead. SHA-256 is appropriate for password-based key derivation when used in PBKDF2.
HMAC. SHA-256 is the most common hash in HMAC (Hash-based Message Authentication Code) constructions, used to authenticate API requests and messages.
Bitcoin. SHA-256 is used twice (SHA-256d) in Bitcoin's proof-of-work algorithm and for generating wallet addresses.
What SHA-256 Is Not
SHA-256 is not encryption. Encryption is reversible with a key; hashing is a one-way operation. SHA-256 is not suitable for passwords without key stretching (see bcrypt). SHA-256 does not authenticate identity by itself — for that, you need HMAC or a digital signature scheme.
Try It
The SHA-256 tool on Syntaxly computes SHA-256 digests in real time as you type, using the browser's native crypto.subtle.digest API. Your input never leaves the page.