Skip to content
Cryptography

SHA-256

SHA-256 (Secure Hash Algorithm 256-bit) is a cryptographic hash function producing a 256-bit hash. It is part of the SHA-2 family and is used for data integrity verification, password storage, and blockchain technology.

What is SHA-256?

SHA-256 Definition

SHA-256 (Secure Hash Algorithm 256-bit) is a cryptographic hash function belonging to the SHA-2 family, designed by the NSA and published by NIST in 2001. It produces a 256-bit (32-byte) digest from any amount of input data.

How Does SHA-256 Work?

Hash Function Properties

SHA-256 possesses key characteristics of cryptographic hash functions:

  • Deterministic - same data always produces the same hash
  • Fast - hash computation is quick
  • One-way - impossible to recover data from hash
  • Collision resistant - practically impossible to find two different inputs producing the same hash
  • Avalanche effect - small data change drastically changes hash

Example

Input: "Hello"
SHA-256: 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969

Input: "Hello!"  (only exclamation mark added)
SHA-256: 334d016f755cd6dc58c53a86e183882f8ec14f52fb05345887c8a5edd42c87b7

Hashing Process

  1. Padding - padding message to multiple of 512 bits
  2. Parsing - dividing into 512-bit blocks
  3. Initialization - setting initial hash values
  4. Compression - 64 rounds of operations on each block
  5. Finalization - combining results into 256-bit hash

SHA-256 Applications

Integrity Verification

# Checking downloaded file integrity
sha256sum ubuntu-22.04.iso
# Compare with official checksum

Password Storage

Passwords are not stored in plain text, but as hash:

Password: "MyPassword123"
Hash:     e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

Digital Signatures

SHA-256 is used in signature schemes:

  • RSA-SHA256
  • ECDSA with SHA-256
  • SSL/TLS certificates

Blockchain and Cryptocurrencies

  • Bitcoin - proof-of-work based on SHA-256
  • Merkle trees - transaction verification
  • Addresses - wallet address generation

Security Protocols

  • TLS/SSL
  • SSH
  • IPsec
  • S/MIME

SHA Family

AlgorithmHash SizeStatus
SHA-1160 bitDeprecated - known collisions
SHA-224224 bitSecure
SHA-256256 bitRecommended
SHA-384384 bitSecure
SHA-512512 bitSecure
SHA-3224-512 bitLatest standard

SHA-256 vs Other Algorithms

SHA-256 vs MD5

AspectSHA-256MD5
Size256 bit128 bit
SecuritySecureBroken
SpeedSlowerFaster
UseCryptographyOnly non-critical checksums

SHA-256 vs SHA-1

AspectSHA-256SHA-1
Size256 bit160 bit
SecuritySecureDeprecated
CollisionsUnknownFound (2017)

SHA-256 vs bcrypt/Argon2

AspectSHA-256bcrypt/Argon2
PurposeGeneral hashPassword hashing
SpeedFastIntentionally slow
SaltNo built-inBuilt-in
For passwordsNot recommended aloneRecommended

SHA-256 Security

Attack Resistance

  • Brute force - 2^256 possibilities = practically impossible
  • Collisions - no known practical collisions
  • Preimage - no known attacks

Limitations

  • Length extension attack - vulnerable (use HMAC-SHA256)
  • Password hashing - too fast, use bcrypt/Argon2
  • Quantum computing - theoretically vulnerable (Grover’s algorithm reduces security to 128 bit)

Implementation

Usage Examples

Python:

import hashlib
hash = hashlib.sha256(b"Hello").hexdigest()

JavaScript:

const hash = await crypto.subtle.digest('SHA-256', data);

Bash:

echo -n "Hello" | sha256sum

HMAC-SHA256

For message authentication use HMAC:

HMAC-SHA256(key, message)

Best Practices

  1. For passwords - use bcrypt, Argon2, or PBKDF2, not SHA-256 alone
  2. For integrity - SHA-256 is appropriate
  3. For MAC - use HMAC-SHA256
  4. For new projects - consider SHA-3 for future-proofing
  5. Migration from SHA-1/MD5 - prioritize moving to SHA-256

SHA-256 remains one of the most important cryptographic algorithms, forming the foundation of security for many systems and protocols.

Explore our services

Frequently asked questions

+ Can SHA-256 be reversed or broken?

SHA-256 is a one-way function — the input data cannot be reconstructed from the hash alone, and no practical attacks are currently known that would break the algorithm or find a collision. A theoretical risk is posed by future quantum computers, but even Grover's algorithm would only weaken SHA-256 to a level equivalent to 128 bits of security, which is still considered safe.

+ How does SHA-256 differ from MD5 and SHA-1?

MD5 and SHA-1 are now considered obsolete and insecure — practical collision attacks have been demonstrated for both, so they should not be used for security purposes. SHA-256, part of the SHA-2 family, generates a 256-bit hash and remains the recommended standard for digital signatures, certificates and data integrity verification.

+ Is SHA-256 suitable for storing passwords?

SHA-256 on its own is too fast to store passwords securely — this facilitates brute-force and rainbow-table attacks. For passwords, dedicated, deliberately slow algorithms with a salt are used, such as bcrypt, scrypt or Argon2. SHA-256, however, works well for verifying file integrity, digital signatures and certificates.

+ Where is SHA-256 used in practice?

SHA-256 is used to verify the integrity of files and software (checksums), in SSL/TLS certificates and digital signatures, in authentication mechanisms (HMAC) and in blockchain technology — among others in Bitcoin and in Merkle tree structures. It is one of the most widely used hash algorithms in modern cryptography.

Tags:

sha256 hash cryptography data integrity blockchain

Want to Reduce IT Risk and Costs?

Book a free consultation - we respond within 24h

Response in 24h Free quote No obligations

Or download free guide:

Download NIS2 Checklist