← Cryptography guide

K050 / Hashes, MACs and key derivation

SHA-2

SHA-256 SHA-2 family · Survey date 2026-12-05

SHA-2 is a family of cryptographic hash functions including SHA-224/256/384/512 and SHA-512/224, SHA-512/256.

CRYPTOGRAPHY LAB / K050

Cryptography Lab · SHA-2

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Limited implementation

SHA-256

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

Definition and overview
SHA-2 is a family of cryptographic hash functions including SHA-224/256/384/512 and SHA-512/224, SHA-512/256. Source document ↗
Classification and reversibility
SHA-256 is a hash function, not encryption; it has no key or decryption and is not reversible. Source document ↗
Key or secret requirements
No key or secret is required, and there is no decryption key. Source document ↗
Operating principle and structure
SHA-256 uses 512-bit blocks, 32-bit words and 64 rounds; SHA-512 uses 1024-bit blocks, 64-bit words and 80 rounds. Source document ↗
Key size, block size and parameters
The SHA-2 family comprises six hash functions producing 224-, 256-, 384- or 512-bit digests. Source document ↗
Security strength and recommendation
NIST recommends SHA-2 or SHA-3 instead of SHA-1 for federal agencies. Source document ↗
Known attacks and vulnerabilities
SHA-256 is susceptible to length-extension attacks; particular care is required when hashing secret messages. Source document ↗
Standards and certification
FIPS 180-4 specifies the SHA-2 family as standard hash algorithms. Source document ↗
Typical uses
Used in certificate signatures, software checksums, Bitcoin proof of work and some signature schemes. Source document ↗
Implementations, libraries and tools
Python's hashlib provides sha256() to create a SHA-256 hash object. Source document ↗
Decryption or decoding
SHA-256 cannot be decrypted; verification consists of recomputing and comparing the digest for the same input. Source document ↗
Advantages
No practical collision attack against SHA-256 is known. Source document ↗
Limitations and cautions
Plan algorithm replacement and upgrades in advance. Source document ↗
Distinguishing encryption, encoding and hashing
SHA-256 is hashing rather than encryption; do not confuse it with keys or decryption. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Feeding a message into SHA-256 produces a fixed-length 256-bit digest. Identical input produces identical digests, and the original cannot be recovered from the digest alone. It is used to compare hashes of original content in file checksums or signature verification.

Procedure

SHA-256 is hashing, not encryption/decryption: (1) input bytes to obtain a fixed-length digest; (2) if needed, compare the recomputed digest with the stored value to check integrity. Encryption transforms plaintext into ciphertext using a key, decryption reverses it with a key, and encoding changes representation with decoding as its inverse; distinguish these from SHA-256.

Scenario

Publish the SHA-256 checksum of a distribution file and have the user hash the downloaded file again and compare to verify integrity. It is used as a hashing component in TLS and certificate signing; use a dedicated KDF instead of SHA-256 alone for password storage.

Pitfalls and alternatives

Do not mistake SHA-256 for encryption or a standalone password-storage KDF. Use keyed MACs such as HMAC-SHA-256 for secret-based integrity and authentication, and dedicated KDFs such as bcrypt, scrypt or Argon2 for password storage. Be aware of length-extension attacks and compare digests in constant time.

Diagram source ↗

References