The cryptographic hash function that secures proof-of-work. Type any message and watch SHA-256 transform it, step by step.
SHA-256 (Secure Hash Algorithm 256-bit) takes any input and produces a fixed 256-bit (32-byte) hash. It's a one-way function — you can't reverse it. Every Bitcoin and Quai block header is hashed with SHA-256 to produce proof-of-work.
The input message is converted to binary, then padded so its total length is a multiple of 512 bits. Padding adds a 1 bit, then zeros, then the original message length as a 64-bit integer.
SHA-256 uses 8 initial hash values (H₀–H₇) derived from the square roots of the first 8 primes, and 64 round constants (K₀–K₆₃) from the cube roots of the first 64 primes. These are nothing-up-my-sleeve numbers — you can verify them yourself.
The 512-bit block is split into 16 words of 32 bits each (W₀–W₁₅). Then 48 more words are generated using bitwise operations, expanding 16 words into 64 words that feed the compression function.
This is the heart of SHA-256. Eight working variables (a–h) are initialized from the current hash values, then transformed through 64 rounds of mixing using bitwise operations.
After all 64 rounds, the working variables are added back to the initial hash values. The resulting 8 × 32-bit words are concatenated to produce the final 256-bit hash.
Change a single bit in the input and roughly 50% of output bits flip. This is what makes SHA-256 secure — there's no way to predict how the hash will change from small input changes. This property is critical for mining: you can't shortcut the search for a valid nonce.