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
- Padding - padding message to multiple of 512 bits
- Parsing - dividing into 512-bit blocks
- Initialization - setting initial hash values
- Compression - 64 rounds of operations on each block
- 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
| Algorithm | Hash Size | Status |
|---|---|---|
| SHA-1 | 160 bit | Deprecated - known collisions |
| SHA-224 | 224 bit | Secure |
| SHA-256 | 256 bit | Recommended |
| SHA-384 | 384 bit | Secure |
| SHA-512 | 512 bit | Secure |
| SHA-3 | 224-512 bit | Latest standard |
SHA-256 vs Other Algorithms
SHA-256 vs MD5
| Aspect | SHA-256 | MD5 |
|---|---|---|
| Size | 256 bit | 128 bit |
| Security | Secure | Broken |
| Speed | Slower | Faster |
| Use | Cryptography | Only non-critical checksums |
SHA-256 vs SHA-1
| Aspect | SHA-256 | SHA-1 |
|---|---|---|
| Size | 256 bit | 160 bit |
| Security | Secure | Deprecated |
| Collisions | Unknown | Found (2017) |
SHA-256 vs bcrypt/Argon2
| Aspect | SHA-256 | bcrypt/Argon2 |
|---|---|---|
| Purpose | General hash | Password hashing |
| Speed | Fast | Intentionally slow |
| Salt | No built-in | Built-in |
| For passwords | Not recommended alone | Recommended |
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
- For passwords - use bcrypt, Argon2, or PBKDF2, not SHA-256 alone
- For integrity - SHA-256 is appropriate
- For MAC - use HMAC-SHA256
- For new projects - consider SHA-3 for future-proofing
- 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.