Skip to main content
Category: Cryptography Fundamentals

SHA-256

Also known as: Secure Hash Algorithm 256-bit, SHA-2 (256-bit variant)
Simply put

SHA-256 is a hash algorithm that takes any input and produces a fixed-length digest, or fingerprint, of that input. This digest can be used to detect whether a message has been changed, because even a small change to the input produces a very different output. It is one of the SHA-2 family of functions that succeeded the older SHA-1.

Formal definition

SHA-256 is a cryptographic hash algorithm in the SHA-2 family that generates a 256-bit (32-byte) message digest, typically represented as a hexadecimal string. It maps an arbitrary-length input to a fixed-length digest and is used to detect whether messages have been altered since the digest was computed. It is described as a successor to SHA-1 and can be used within constructions such as HMAC. Note that hashing differs from tokenization, encryption, truncation, and masking; each transforms data differently, and its effect on PCI DSS scope depends on implementation and validation rather than the algorithm label alone. Readers should confirm approved algorithms and key-strength expectations against the current published standards.

Why it matters

SHA-256 matters because it provides a way to detect whether a message has been altered since its digest was computed. Because even a small change to the input produces a very different output, comparing a recomputed digest against a stored one helps identify tampering or corruption. This integrity-checking property makes hash functions foundational to many security and compliance workflows, from verifying file integrity to underpinning constructions such as HMAC for message authentication.

SHA-256 is part of the SHA-2 family, described as a successor to the older SHA-1 and as one of the stronger hash functions available. When teams evaluate cryptographic controls, the choice of hash algorithm affects how much confidence they can place in integrity and authentication mechanisms. Selecting a well-regarded function from the SHA-2 family, rather than relying on weaker legacy algorithms, is part of maintaining defensible cryptographic practice.

It is important not to conflate hashing with other data transformations. Hashing differs from tokenization, encryption, truncation, and masking, and each of these affects data differently. The effect any of them has on PCI DSS scope depends on how it is implemented and validated, not on the algorithm label alone. Sensitive authentication data such as full track data, CAV2/CVC2/CVV2/CID, and PINs or PIN blocks must not be stored after authorization even when transformed, so applying a hash function does not by itself create a compliant storage path. Readers should confirm approved algorithms and key-strength expectations against the current published standards rather than assuming any algorithm is sufficient on its own.

Who it's relevant to

Security engineers
Engineers implementing integrity checks or message authentication may use SHA-256 to generate digests that detect whether data has changed, and as the underlying hash in constructions such as HMAC. They should distinguish hashing from tokenization, encryption, truncation, and masking, since each transforms data differently, and confirm approved algorithms and key strengths against the current published standards.
Compliance officers
Compliance teams evaluating cryptographic controls should recognize that the effect of hashing on PCI DSS scope depends on implementation and validation, not on the algorithm label alone. Applying SHA-256 does not by itself authorize storage of data, and sensitive authentication data must not be stored after authorization even when transformed. Approved algorithm and key-strength expectations should be confirmed against the current published standard.
Application developers
Developers can use SHA-256 to produce fixed-length digests for integrity verification across various input encodings. They should treat it as a successor to weaker legacy functions such as SHA-1 and understand that a hash alone does not equal a compliant data-protection design; the surrounding controls and validation determine its security value.

Inside SHA-256

Cryptographic hash function
SHA-256 is a member of the SHA-2 family that produces a fixed-length 256-bit (32-byte) output, commonly represented as a 64-character hexadecimal string, from an input of arbitrary length.
One-way transformation
SHA-256 is designed to be computationally infeasible to reverse, meaning the original input cannot practically be derived from the hash output alone.
Deterministic output
The same input always produces the same hash value, which is why unsalted hashing of predictable inputs such as a PAN can be vulnerable to brute-force or lookup attacks.
Collision resistance
SHA-256 is intended to make it computationally difficult to find two distinct inputs that produce the same output, though this property is a design goal subject to ongoing cryptographic evaluation.
Relationship to PAN handling
Hashing can be used as one method to render a PAN unreadable, but its effect on PCI DSS scope depends on implementation and validation, not on the use of the label 'hashed' alone. Where the hash and truncated version of the same PAN are both present, additional controls may be needed to prevent correlation.

Common questions

Answers to the questions practitioners most commonly ask about SHA-256.

Does hashing a PAN with SHA-256 make it acceptable to store sensitive authentication data?
No. Hashing a PAN with SHA-256 is a technique that may be applied to cardholder data such as the Primary Account Number, but it does not change the rule that sensitive authentication data (full track data, CAV2/CVC2/CVV2/CID, and PINs or PIN blocks) must not be stored after authorization, even when hashed or otherwise transformed. SHA-256 relates to how certain cardholder data may be rendered unreadable; it does not create an exception permitting retention of sensitive authentication data.
Is SHA-256 the same as tokenization or encryption for protecting a PAN?
No. SHA-256 is a one-way hash function, which transforms data differently from encryption, tokenization, truncation, or masking. Encryption is reversible with the appropriate key, tokenization substitutes a surrogate value, and truncation and masking remove or hide portions of the PAN. A hash is not designed to be reversed. These approaches reduce or transform data in different ways, and their effect on PCI DSS scope depends on implementation and validation rather than on the label alone.
When SHA-256 is used to render a PAN unreadable, what implementation considerations apply?
Because a PAN has a limited and predictable structure, an unsalted or poorly implemented hash may be susceptible to brute-force or lookup attacks. Where hashing is used to render a PAN unreadable in stored form, the implementation and any associated inputs should be evaluated against the requirements of the current published PCI DSS version. Confirm the applicable requirement wording against the standard in force rather than assuming a fixed requirement number, as numbering and wording differ between versions.
Can a hashed PAN and a truncated version of the same PAN be stored together?
Storing a hashed version and a truncated version of the same PAN can, in combination, create a risk that the original PAN could be reconstructed or correlated. This is a recognized implementation concern, and controls should be applied so that the two representations cannot be readily correlated to recover the full PAN. Validate the approach against the current PCI DSS requirements rather than relying on the labels of the techniques used.
Does using SHA-256 by itself take a system out of PCI DSS scope?
Applying SHA-256 does not automatically remove a system from scope. The effect of any data-rendering technique on scope depends on how it is implemented and validated, including how inputs are handled and whether the original data remains recoverable within the environment. Scope determinations should be based on assessment against the current standard, not on the presence of a particular algorithm.
What are the limitations of relying on SHA-256 to protect stored cardholder data?
SHA-256 is a one-way function and does not, on its own, address key management, access control, retention limits, or the prohibition on storing sensitive authentication data. Its protective value depends on correct implementation and on complementary controls. It is intended to help render certain cardholder data unreadable when applied appropriately, but it is not a standalone control and does not guarantee protection. Evaluate its use as part of a broader control set validated against the current PCI DSS version.

Common misconceptions

Hashing a PAN with SHA-256 is the same as encrypting it, so the data is protected either way.
Hashing and encryption are distinct. Encryption is reversible with a key, while a hash is a one-way transformation that cannot be decrypted back to the original value. They transform data differently, and their effect on PCI DSS scope depends on implementation and validation rather than on the label used.
Because SHA-256 is one-way, an unsalted hash of a PAN can never be reversed.
SHA-256 is deterministic and PANs follow a constrained, predictable structure, which makes unsalted hashes susceptible to brute-force and precomputed lookup attacks. Rendering a PAN unreadable through hashing generally requires additional measures, and validation against the current PCI DSS standard should confirm the approach.
SHA-256 can be used to protect sensitive authentication data for later use.
Sensitive authentication data such as full track data, CAV2/CVC2/CVV2/CID, and PINs or PIN blocks must not be stored after authorization, even when encrypted or hashed. Applying SHA-256 does not create an exception to this prohibition.

Best practices

Do not rely on unsalted hashing of a PAN, because the constrained structure of card numbers makes deterministic hashes vulnerable to brute-force and lookup attacks; add appropriate measures where hashing is used to render a PAN unreadable.
Never use SHA-256 or any hashing method as a workaround to retain sensitive authentication data, which must not be stored after authorization regardless of the transformation applied.
Where both a hashed and a truncated version of the same PAN exist, apply controls to prevent the two from being correlated to reconstruct the original value.
Distinguish clearly between hashing, encryption, truncation, and masking in your data-handling documentation, since each transforms data differently and has different implications for PCI DSS scope.
Validate any hashing-based approach to rendering cardholder data unreadable against the current published PCI DSS standard rather than assuming a specific requirement number, as wording and numbering differ between versions.
Treat the security properties of SHA-256, such as collision and preimage resistance, as design goals subject to ongoing cryptographic evaluation, and monitor guidance for changes affecting acceptable algorithms.