Skip to content
FoundationSource checked

SHA-256

Computes a fixed 256-bit cryptographic hash of an input message.

Quick Facts

Compact metadata for implementation and discovery.

Category
Cryptography
Difficulty
Advanced
Family
Cryptographic Hash
Tier
Foundation
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
9
Code example
Not ready
Visualization
Ready
Aliases
SHA256

Overview

SHA-256 processes message blocks through a compression function to produce a 256-bit digest. Small input changes are designed to produce unpredictable digest changes.

Core Concepts

cryptographic hashmessage blockcompression functiondigest

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n)

Worst

O(n)

Space

O(1)

When to Use

  • Use it for integrity checks, content addressing, and cryptographic protocols that specify SHA-256.
  • Use HMAC-SHA-256 when a keyed message authentication code is required.
  • Use vetted library implementations.

When Not to Use

  • Avoid using plain SHA-256 as password storage without a password-hashing scheme.
  • Avoid treating a hash digest as encryption.
  • Avoid using it as a MAC without a construction such as HMAC.

What It Does

  • Hashes data to a fixed-size digest
  • Makes small input changes produce very different output

Use Cases

  • Integrity checks
  • Digital signatures
  • Content addressing

Inputs

  • Message bytes

Outputs

  • 256-bit digest

Key Formulas (1)

Compression round value

T1 = h + Σ₁(e) + Ch(e, f, g) + K[t] + W[t]
T1 = h + Sigma1(e) + Ch(e, f, g) + K[t] + W[t]

Combines state words, constants, and message schedule data in each compression round.

Pseudocode

  1. 1.Pad the message to a block boundary
  2. 2.Initialize fixed hash state values
  3. 3.Process each block through compression rounds
  4. 4.Update the hash state after each block
  5. 5.Return the final digest

Canonical Example

Input
message bytes = "abc"
Output
a 256-bit digest
Explanation
SHA-256 deterministically maps the byte string to a fixed-length digest used for integrity or identification.

Implementation Notes

  • Feed bytes in the exact encoding expected by the protocol.
  • Use streaming APIs for large inputs.
  • Use constant-time comparison when checking keyed digests.

Common Pitfalls

  • Assuming hashes can be decrypted.
  • Using raw hashes for passwords instead of salted, slow password hashing.
  • Comparing secret-dependent digests with non-constant-time equality checks.

Interactive Mechanism Walkthrough

Graph Frontier & Edge Relaxation

Show message blocks updating a fixed-size hash state.

SHA-256 mechanism walkthrough step 1 of 5suvwxt
Step 1 of 5: Pad the message to a block boundary
hash-blocks

Notes

SHA-256 is not encryption; it is a one-way digest function.

Sources (1)

What each reference supports for this entry.

NIST FIPS 180-4

Documentation

NIST Secure Hash Standard reference for SHA-256 and related SHA-2 hash algorithms.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toBLAKE3

Both are cryptographic hash functions with different designs.

SHA-256 follows a Merkle-Damgard-style compression construction.

Related Algorithms

Tags

CryptographyHashingSecurity