A hash function takes an input of any size and produces a fixed-length output (called a hash, digest, or fingerprint) that uniquely represents the input. Per NIST SP 800-107, cryptographic hash functions are one-way: given the hash, you can't recover the original data. Even a single bit change in the input produces a completely different hash.
Key takeaways
- Hashing is a one-way function: you can produce a hash from data but can't reverse it.
- SHA-256 is the standard for data integrity. bcrypt/Argon2 are the standard for password storage.
- MD5 and SHA-1 are broken for security purposes. Per NIST, don't use them.
- Always salt password hashes. Per OWASP, each password needs a unique random salt.
- Hashing is not encryption. Encryption is reversible; hashing is not.
Quick explanation
In simple terms
Hashing converts data into a fixed-length code (like a digital fingerprint) that can't be reversed. It's used to store passwords safely, verify file integrity, and sign documents.
Technical definition
A cryptographic hash function is a deterministic, one-way function H(x) that maps arbitrary-length input to a fixed-length output with three security properties: pre-image resistance, second pre-image resistance, and collision resistance (per NIST SP 800-107).
Analogy
A hash function is like a fingerprint scanner. It takes your finger (input) and produces a unique fingerprint (hash). You can't reconstruct the finger from the fingerprint, but you can compare two fingerprints to see if they match.
Definition
Hashing is a one-way cryptographic function that converts input data of any size into a fixed-length output (hash/digest). Per NIST, the output can't be reversed to recover the original data, and even tiny input changes produce completely different hashes.
Hashing is a fundamental cryptographic operation that converts input data of any size into a fixed-length output called a hash, digest, or fingerprint. Per NIST SP 800-107, a cryptographic hash function must be deterministic (same input always produces same output), one-way (infeasible to reverse), and collision-resistant (infeasible to find two inputs with the same hash).
Hash functions are used across IT: password storage (bcrypt, Argon2), file integrity verification (SHA-256 checksums), digital signatures, certificate validation, blockchain, data deduplication, and content-addressable storage. Different use cases require different algorithms: general-purpose hashes (SHA-256) prioritize speed, while password hashes (bcrypt) prioritize slowness to resist brute-force attacks.
Why it matters
Core concepts
Hash function
A function that converts an input of any size into a fixed-size output that cannot be reversed.
Per NIST SP 800-107, a cryptographic hash function must satisfy three properties: pre-image resistance (can't find the input from the hash), second pre-image resistance (can't find a different input with the same hash), and collision resistance (can't find any two inputs with the same hash).
Example
SHA-256 of 'hello' always produces 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824.
Why it matters — Hash functions are the building block of password security, digital signatures, and blockchain. A broken hash function (like MD5) undermines all systems that depend on it.
Salt
Random data added to the input before hashing, ensuring identical inputs produce different hashes.
Without a salt, identical passwords produce identical hashes, making rainbow table attacks trivial. Per OWASP, every password should have a unique, randomly generated salt stored alongside the hash.
Example
User A and User B both use password 'admin123', but their hashes differ because each has a unique random salt.
Why it matters — Salting defeats precomputed rainbow table attacks and prevents attackers from identifying users with the same password.
Collision
When two different inputs produce the same hash output.
Collision resistance is a key property of secure hash functions. When collisions become practical to find, the hash function is considered broken for security purposes. Per NIST, MD5 and SHA-1 are deprecated for security applications due to demonstrated collision attacks.
Example
Researchers demonstrated practical SHA-1 collisions in 2017 (SHAttered attack), proving SHA-1 is unsuitable for security applications.
Why it matters — Hash collision attacks can forge digital signatures, create malicious files with the same hash as legitimate ones, and bypass integrity checks.
How it works
Input is fed to the hash function
The hash function receives input data of any size: a password string, a file, or a block of data. The input is processed in fixed-size blocks.
Input data → Hash function
Mathematical transformation
The algorithm applies a series of mathematical operations (bitwise operations, modular arithmetic, compression functions) to transform the input through multiple rounds. SHA-256 uses 64 rounds.
64 rounds of transformation
Fixed-length output (digest)
The function outputs a fixed-length hash value (digest). SHA-256 always produces 256 bits regardless of input size. Even a single bit change in input produces a completely different output (avalanche effect).
Fixed-length digest output
Benefits
One-way: can't reverse the hash
Hash functions are one-way: given a hash output, it's computationally infeasible to recover the original input. This makes them ideal for password storage.
Collision-resistant integrity verification
Even a single bit change in the input produces a completely different hash. This makes hashes reliable for verifying file integrity and detecting tampering.
Fixed-length output
Regardless of input size (1 byte or 1 TB), the hash output is always the same length (e.g., 256 bits for SHA-256). This makes storage and comparison efficient.
Limitations
MD5 and SHA-1 are broken for security
HighPer NIST, MD5 and SHA-1 have demonstrated collision attacks and should not be used for security applications. MD5 collisions can be generated in seconds on modern hardware.
Workaround — Use SHA-256 (SHA-2 family) for integrity verification. Use bcrypt, Argon2, or scrypt for password hashing.
Fast hashes are unsuitable for passwords
HighGeneral-purpose hash functions like SHA-256 are designed to be fast. For password hashing, speed is a liability because attackers can try billions of guesses per second.
Workaround — Per OWASP, use deliberately slow password hashing algorithms: Argon2id (preferred), bcrypt, or scrypt.
Examples
Password storage with bcrypt
A web application stores user passwords using bcrypt with a cost factor of 12.
Per OWASP, bcrypt is designed to be slow (configurable cost factor) to resist brute-force attacks. It generates a unique salt automatically and stores it with the hash. A cost factor of 12 means 2^12 iterations.
File integrity verification with SHA-256
An IT admin verifies a downloaded ISO file hasn't been tampered with by comparing its SHA-256 hash against the vendor's published hash.
SHA-256 produces a unique 256-bit fingerprint of the file. If a single byte changes (due to corruption or tampering), the hash is completely different. Tools: sha256sum (Linux), Get-FileHash (PowerShell), certutil (Windows).
Comparisons
Hashing vs. Encryption
Hash functions vs. KDFs
Myths, corrected
Myth
SHA-256 is a good algorithm for storing passwords
Correction
SHA-256 is fast by design, which makes it unsuitable for password storage. A modern GPU can compute billions of SHA-256 hashes per second. Per OWASP, use bcrypt, Argon2, or scrypt, which are deliberately slow and memory-intensive.
Why it happens: SHA-256 is secure for integrity verification, so people assume it's also good for passwords. But the security requirements are different: integrity needs speed, passwords need slowness.
Myth
Hashing makes data secure and unrecoverable
Correction
Hashing without a salt is vulnerable to rainbow table attacks. Per OWASP, precomputed tables can reverse unsalted hashes of common passwords in seconds. Always use a unique random salt per password.
Why it happens: People conflate 'one-way function' with 'unbreakable.' The one-way property only holds when combined with salting and appropriate algorithm choice.
Practical implications
For admins
Verify that your applications use bcrypt/Argon2 for password storage, not MD5 or plain SHA-256. Check file integrity with SHA-256 checksums when downloading software.
For business
Hash-based security failures (like storing passwords in MD5) lead to data breaches. Per NIST, using deprecated hash functions is a compliance risk.
For security
Audit password storage implementations for unsalted or weak hashing. Monitor for credential stuffing attacks that exploit leaked hash databases.
Decision guide
Use when
- Storing passwords (use bcrypt, Argon2, or scrypt with salt).
- Verifying file integrity (use SHA-256).
- Creating digital signatures.
- Data deduplication and content-addressable storage.
Alternatives
- Encryption (when data retrieval is needed)
- HMAC (for message authentication with a secret key)
- Digital signatures (for non-repudiation with asymmetric keys)
Related terms
Salt
Random data added to input before hashing to prevent rainbow table attacks.
HMAC
A hash-based message authentication code combining a hash function with a secret key.
bcrypt
An algorithm for password hashing based on the Blowfish cipher with adjustable cost factor.
Frequently asked questions
Is hashing the same as encryption?
No. Hashing is one-way: you can't recover the original data from a hash. Encryption is two-way: you can decrypt with the correct key. Per OWASP, always hash passwords; never encrypt them.
Is MD5 still secure?
Per NIST SP 800-107, MD5 is broken for security applications due to practical collision attacks. It should not be used for password hashing, digital signatures, or integrity verification in security contexts.
What is a salt in hashing?
A salt is random data added to the input before hashing. Per OWASP, it ensures identical passwords produce different hashes, defeating rainbow table attacks. Each password should have a unique random salt.
Which hashing algorithm should I use for passwords?
Per OWASP Password Storage Cheat Sheet, use Argon2id (preferred), bcrypt, or scrypt. These are deliberately slow to resist brute-force attacks. Never use SHA-256 or MD5 directly for passwords.
What is a rainbow table attack?
A precomputed table mapping common passwords to their hash values. Without salting, an attacker can look up a hash in the rainbow table to find the password instantly instead of brute-forcing.
How long is a SHA-256 hash?
SHA-256 produces a 256-bit (32-byte) hash, displayed as a 64-character hexadecimal string. It's the most widely used member of the SHA-2 family, per NIST.
Conclusion
Hashing converts arbitrary data into a fixed-length fingerprint using a one-way function. It's the foundation of password security, file integrity verification, digital signatures, and blockchain.
Per NIST and OWASP, use purpose-built password hashing algorithms (bcrypt, Argon2, scrypt) with unique salts, not general-purpose hash functions (MD5, SHA-256) for credential storage. Per NIST SP 800-107, SHA-256 remains the standard for data integrity and digital signatures.
Main takeaway
Explore HMAC (Hash-based Message Authentication Code) for message authentication, and study how digital signatures combine hashing with asymmetric encryption.






