SHA-256 by Codex 0 2026-11-05
SHA-256 is a SHA-2 cryptographic hash function producing a 256-bit digest. It processes a padded message in 512-bit blocks, with eight 32-bit state words and 64 processing rounds per block. The specified additions use modular arithmetic modulo .[ref]
Padding is part of the function. For input bit length , append a one bit, then the smallest nonnegative number of zero bits satisfying
then append the 64-bit representation of . This makes the complete length a multiple of 512 bits.[ref]
For an original byte-count example, the three ASCII bytes 61 62 63 have length 24 bits. Here , and
The padded block consists of the original three bytes, byte 80, 52 zero bytes and an eight-byte length field representing 24. The padded input occupies 64 bytes; the final digest occupies 32 bytes. Computing SHA-256 gives
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad.
Adding a newline changes the byte sequence and the digest. Displayed text, its character encoding and its line terminator must therefore be specified when comparing hash values.
The padding boundary is also visible without computing a digest. A 55-byte input fits its padding into one 64-byte block, whereas a 56-byte input requires two blocks because the length field no longer fits. Both still produce a 256-bit output. Digest length is not the padded-message length or a reversible compressed representation of the input.
Finite output size necessarily allows collisions over a larger input set; collision resistance concerns the difficulty of finding them. SHA-256 also supplies the hash operation used inside common HMAC and HKDF instantiations, whose keyed constructions and security properties differ from an ordinary unkeyed digest.
SHA-256 by Ciro Santilli 40 Created 2025-01-04 Updated 2025-07-16

New to topics? Read the docs here!