Identifiers & Security

SHA-256 Explained: How Hashing Works and Why It Matters

What SHA-256 does, how it differs from encryption, and where it shows up in everyday software, from passwords to Git commits.

7 min read Last updated 2026-07-19 Luis Avila
SHA-256 Explained: How Hashing Works and Why It Matters explains SHA-256 hashing from the concepts that matter most to the decisions you make in practice. It focuses on how the technology works, where it fits, the tradeoffs to check, and how to avoid results that look correct but fail in a real workflow.

What will this guide cover?

  • What does SHA-256 produce?
  • How is SHA-256 used?
  • Common applications
  • Hashing vs encryption
  • Practical example
  • Safe implementation
  • Limitations and mistakes

What does SHA-256 produce?

SHA-256 is a cryptographic hash function that converts any amount of input into a fixed 256-bit digest, commonly displayed as 64 hexadecimal characters. The same input produces the same digest, while a small input change produces a very different result. Hashing is one-way and does not provide a way to recover the original data.

How is SHA-256 used?

Applications feed bytes into the hash function, often in chunks, and receive a digest after finalization. The digest can be compared with an expected value to detect accidental or malicious changes. Both sides must hash exactly the same bytes, including character encoding and line endings.

Common applications

SHA-256 is used for file integrity checks, content addressing, digital signatures, certificate systems, and HMAC message authentication. It is also used inside larger protocols. A plain SHA-256 digest is not suitable for storing user passwords because fast hashing makes large-scale guessing inexpensive.

Hashing vs encryption

Encryption is reversible with a key and protects confidentiality. Hashing is not reversible and is normally used for fingerprints and integrity. HMAC combines a hash with a secret key to authenticate a message, while a digital signature uses asymmetric keys and can be verified without sharing the private key.

Practical example

A software publisher can publish the SHA-256 checksum of an installer. After downloading, a user hashes the local file and compares the full digest. A match strongly indicates the file bytes are identical to the publisher’s reference, assuming the checksum itself came from a trusted source.

Safe implementation

Use a maintained cryptographic library, compare full digests, and encode inputs consistently. For password storage, use Argon2id, scrypt, bcrypt, or PBKDF2 with a unique salt and appropriate cost. For authenticated API messages, use HMAC-SHA-256 or a standard signed protocol rather than concatenating a secret manually.

Limitations and mistakes

A hash does not prove who created the data unless it is authenticated. Truncating digests reduces collision resistance, and comparing checksums from the same compromised server provides little protection. Avoid inventing custom combinations of hashing, salts, and encryption when a standard construction already exists.

Frequently Asked Questions

It produces a fixed 256-bit digest for integrity checks, digital signatures, content addressing, and other cryptographic constructions. It maps any input size to a 64-character hexadecimal value.
No practical reverse operation exists. Attackers can still guess likely inputs and hash them, so low-entropy values such as passwords remain vulnerable without a dedicated password-hashing function.
Yes, byte-for-byte identical input produces the same digest. A different text encoding, line ending, hidden byte order mark, or capitalization changes the bytes and therefore the hash.
Not by itself. Use Argon2id, scrypt, bcrypt, or PBKDF2 with a unique salt and appropriate work factor. SHA-256 is intentionally fast, which makes brute-force attacks cheaper.
A salt is a unique random value combined with a password before hashing. It prevents identical passwords from sharing the same stored result and defeats precomputed rainbow tables.
Encryption is reversible with a key. Hashing is a one-way transformation used mainly for comparison and integrity, not for recovering the original content.
Calculate the digest of the downloaded bytes and compare the entire value with one published through a trusted channel. A matching hash checks integrity, but authenticity depends on trusting the published reference.