SHA-256 is a cryptographic hash function in the SHA-2 family that maps variable-length input data to a fixed-size digest. SHA stands for Secure Hash Algorithm, and 256 identifies the digest length: 256 bits, or 32 bytes. The output is commonly displayed as 64 hexadecimal characters, but hexadecimal is only a representation; the digest can also be stored as raw bytes.
How It Works
SHA-256 operates on data, not just readable text: files, binary records and encoded messages can all be inputs. Identical input bytes always produce the same digest, enabling repeatable comparisons. Even a one-bit change generally produces a substantially different digest, a property called the avalanche effect. Text encoding, spaces and line endings therefore matter when comparing results.
The algorithm first pads the input, including its original message length, then processes the padded data in 512-bit blocks. It starts with an internal state of eight 32-bit words. For each block, 64 rounds of bitwise operations and modular addition transform working values initialized from that state. The resulting values are added back into the accumulated state before the next block is processed. After all blocks, the eight final state words are joined to form the digest.
Security Properties
SHA-256 produces a digest, not recoverable ciphertext, and has no decryption key. Encryption, by contrast, is designed to allow recovery of the original data with the appropriate key.
Preimage resistance means that finding an input for a given digest is computationally difficult. It does not prevent guessing a likely input and checking whether its hash matches. Collision resistance means that finding two different inputs with the same digest is computationally difficult. Collisions necessarily exist because the fixed-size output space is smaller than the space of possible inputs; resistance is not a guarantee of uniqueness.
FinchTrade Promotion. The following brand message is separate from this technical reference and is not an offer of cryptographic-security guidance.
Looking for liquidity, exploring on-ramp/off-ramp services, or seeking expert guidance?
Get startedIntegrity Checks and Authentication
To check a file with SHA-256, calculate its digest and compare it with an expected digest obtained through a trusted channel. A mismatch reveals a difference; a match provides strong evidence of matching content, but does not independently identify who supplied it. An attacker who can replace both the file and its published digest defeats a bare comparison.
Digital signature schemes can use a message digest when creating and verifying signatures, but hashing alone does not authenticate a sender. In TLS, the protocol behind HTTPS, the hash can participate in signatures, keyed authentication constructions and key derivation. These constructions combine hashing with other cryptographic operations and, where required, secret keys. Separate encryption algorithms provide traffic confidentiality; a digest does not encrypt network traffic.
Bitcoin Proof of Work
Bitcoin miners repeatedly apply double SHA-256 to candidate block headers, hashing each header and then hashing the resulting digest. They vary header data to find a result at or below the network's numerical difficulty target. Leading zeros are a simplified visual description of a low hash value, not the full acceptance rule. Hashing supports proof of work and references to previous blocks, but other validation rules and consensus mechanisms remain necessary. A qualifying hash does not, by itself, make invalid transactions valid.
Password Storage Limitations
SHA-256 is designed for efficient computation, which benefits file checks but makes it unsuitable on its own for password storage. After a password-database leak, attackers can rapidly hash candidate passwords and compare the results with stored digests. One-way processing does not protect predictable passwords from this guessing process. Password storage should instead use a purpose-built, salted, deliberately costly password-hashing scheme, such as Argon2id. A salt alone does not make a fast general-purpose hash suitable for password storage.