What is SHA-256?
SHA-256 is a member of the SHA-2 family of cryptographic hash functions, standardized by NIST. It takes an input message of any length and produces a fixed 256-bit (32-byte) digest, displayed here as 64 hexadecimal characters. The same input always yields the same digest, while even a one-character change produces a completely different output (the avalanche effect). SHA-256 is widely used in TLS certificates, digital signatures, blockchain (Bitcoin), and file-integrity checks.
How to use this calculator
Type or paste any text into the input box and submit. The calculator UTF-8 encodes your text, runs the SHA-256 algorithm, and returns the hexadecimal digest along with the input's byte length. An empty input is valid and produces the well-known empty-string digest.
The formula explained
The core operation is:
$$\text{Hash} = \operatorname{SHA\text{-}256}\!\left(\text{Input Text}\right)$$SHA-256 pads the message so its length is a multiple of 512 bits, splits it into 512-bit blocks, and processes each block through 64 rounds of bitwise operations (rotations, shifts, AND/XOR, modular addition) mixing eight 32-bit working variables initialized from fractional parts of square roots of primes. The eight registers are added back into the running hash state after each block; concatenating them gives the final 256-bit digest.
Worked example
The input abc (3 bytes) produces the digest ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad. The empty string produces e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 — a standard test vector.
SHA-256 Constants and Initial Hash Values
SHA-256 is part of the SHA-2 family standardized by NIST in FIPS 180-4. It works on 32-bit words, processes the message in 512-bit blocks, and appends the message length as a 64-bit big-endian integer. All additions are done modulo \(2^{32}\).
Initial hash values H0–H7
The eight starting values are the first 32 bits of the fractional parts of the square roots of the first eight primes (2, 3, 5, 7, 11, 13, 17, 19):
| Register | Prime | Initial value (hex) |
|---|---|---|
| H0 | 2 | 6a09e667 |
| H1 | 3 | bb67ae85 |
| H2 | 5 | 3c6ef372 |
| H3 | 7 | a54ff53a |
| H4 | 11 | 510e527f |
| H5 | 13 | 9b05688c |
| H6 | 17 | 1f83d9ab |
| H7 | 19 | 5be0cd19 |
Formally, for the prime \(p_i\): $$H_i = \left\lfloor \left(\sqrt{p_i} - \lfloor \sqrt{p_i} \rfloor\right) \cdot 2^{32} \right\rfloor$$ For example, \(\sqrt{2} \approx 1.41421356\), and its fractional part times \(2^{32}\) gives 0x6a09e667.
Round constants K0–K63
The 64 round constants are derived the same way, but from the cube roots of the first 64 primes (2 through 311): $$K_t = \left\lfloor \left(\sqrt[3]{p_t} - \lfloor \sqrt[3]{p_t} \rfloor\right) \cdot 2^{32} \right\rfloor$$ The first few are 428a2f98, 71374491, b5c0fbcf and e9b5dba5. Because they come from a transparent formula rather than arbitrary choices, they are "nothing-up-my-sleeve" numbers.
Size parameters
- Word size: 32 bits
- Block size: 512 bits (64 bytes, 16 words)
- Length field: 64 bits, appended at the end of the padded message
- Output: 256 bits, shown as 64 hexadecimal characters
How SHA-256 Is Computed Step by Step
- UTF-8 encode the input. The text is converted to bytes. ASCII characters take 1 byte each, while other characters take 2 to 4 bytes. The hash is computed over these bytes, not over the characters.
- Pad the message. Append a single 1 bit (the byte 0x80), then add 0 bits until the length is 448 mod 512. Finally append the original message length in bits as a 64-bit big-endian integer.
- Split into 512-bit blocks. Each block is read as sixteen 32-bit big-endian words \(W_0 \dots W_{15}\).
- Build the message schedule. For \(16 \le t < 64\): $$W_t = \sigma_1(W_{t-2}) + W_{t-7} + \sigma_0(W_{t-15}) + W_{t-16}$$ where \(\sigma_0(x) = \text{ROTR}^7(x) \oplus \text{ROTR}^{18}(x) \oplus \text{SHR}^3(x)\) and \(\sigma_1(x) = \text{ROTR}^{17}(x) \oplus \text{ROTR}^{19}(x) \oplus \text{SHR}^{10}(x)\).
- Run 64 compression rounds. Start with working variables a–h set to the current hash state. In each round compute $$T_1 = h + \Sigma_1(e) + \text{Ch}(e,f,g) + K_t + W_t,\quad T_2 = \Sigma_0(a) + \text{Maj}(a,b,c)$$ with \(\text{Ch}(e,f,g) = (e \wedge f) \oplus (\lnot e \wedge g)\), \(\text{Maj}(a,b,c) = (a \wedge b) \oplus (a \wedge c) \oplus (b \wedge c)\), \(\Sigma_0(a) = \text{ROTR}^2 \oplus \text{ROTR}^{13} \oplus \text{ROTR}^{22}\) and \(\Sigma_1(e) = \text{ROTR}^6 \oplus \text{ROTR}^{11} \oplus \text{ROTR}^{25}\). Then shift the variables: h←g, g←f, f←e, e←d+T1, d←c, c←b, b←a, a←T1+T2.
- Update the hash state. Add a–h to H0–H7 (mod \(2^{32}\)). Repeat steps 4–6 for each further block.
- Output the digest. Concatenate H0 through H7, each as 8 hex digits, giving 64 hex characters.
Padding example: "abc"
The input "abc" is the 3 bytes 0x61 0x62 0x63, which is 24 bits. After padding:
- Message bytes:
61 62 63(24 bits) - Append
80(the 1 bit followed by seven 0 bits); the length is now 32 bits - Append 52 zero bytes so the length reaches 448 bits (24 + 1 + 423 zero bits)
- Append the 64-bit length:
00 00 00 00 00 00 00 18, since 24 = 0x18
Total: 3 + 1 + 52 + 8 = 64 bytes = 512 bits, so one block is enough.
Comparing SHA-256 Digests Across Inputs
Whatever the input length, the SHA-256 digest is always 256 bits, or 64 hexadecimal characters. Changing even one character produces a completely different digest (the avalanche effect). Only digests I am certain of are printed below; for the others, enter the text into the calculator to see the result.
| Input | Characters | UTF-8 bytes | SHA-256 digest |
|---|---|---|---|
| (empty string) | 0 | 0 | e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 |
| abc | 3 | 3 | ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad |
| Abc | 3 | 3 | Unrelated 64-character digest; enter it in the calculator to see it |
| é | 1 | 2 (0xC3 0xA9) | 64-character digest of the 2 UTF-8 bytes; enter it in the calculator to see it |
What the table shows
- Avalanche effect: "abc" and "Abc" differ in a single bit (0x61 vs 0x41 in the first byte), yet their digests share no meaningful similarity. Roughly half of the output bits flip.
- Characters vs. bytes: "é" is one character but two bytes in UTF-8, so the hash is computed over 2 bytes. The same visible character can be encoded differently (for example, a precomposed é versus "e" plus a combining accent), and these give different digests.
- Fixed length: the empty string and a long document both give 64 hex characters.
FAQ
Is SHA-256 reversible? No. It is a one-way function; you cannot recover the input from the digest.
Why is my byte count larger than the character count? Non-ASCII characters (accents, emoji, CJK) take multiple bytes in UTF-8, so the byte length can exceed the number of characters.
Is SHA-256 still secure? Yes. As of today there are no practical collision or preimage attacks against SHA-256; it remains a recommended hash for general use.