What Is Hashing in Cybersecurity?
In cybersecurity, a cryptographic hash maps data to a fixed-length digest. It helps detect changes and is used inside password-hashing schemes and digital signatures. A digest is not encryption, and publishing one does not by itself prove who supplied the data. For password storage, the choice of password-hashing algorithm and its work factor matters as much as the one-way property.
Hashing is one of the quiet workhorses of security. This guide covers what it does, why it's one-way, and how it differs from encryption.
Hashing Is One-Way (That's the Point)
A hash function maps any input to a fixed-length output, and a cryptographic hash makes that mapping practically impossible to reverse. Given the hash, you can't reconstruct the input; and a tiny input change produces a totally different output (the avalanche effect).
SHA-256("correct horse") = 4104d36f8da2c254349f85836793ebe029e0c957063a34c91c2e9203187b5631
SHA-256("correct horsf") = dc1b9b967eb23d8214eb023ad49bde4feb39a0a7e029d369e78e2fc9d86bfd12
The examples hash UTF-8 text without a trailing newline. A digest does not reveal the original input directly, but attackers can guess likely inputs and compare their hashes. Try a non-secret sample in our SHA-256 Hash Generator.
The Three Big Security Uses
1. Password Storage
Systems should not store plaintext passwords. They store the output of a dedicated password hasher such as Argon2id, scrypt, or bcrypt, including its salt and cost parameters. At login, the system verifies a candidate password against that stored value. A breach still enables offline guessing, so weak passwords remain vulnerable. See OWASP's password storage guidance.
2. Data and File Integrity
A digest comparison can detect accidental changes. To detect malicious substitution, you must get the expected digest through a trusted channel or verify a digital signature: an attacker who can replace both file and posted digest can make them match. Git uses hashes to identify content, but repository trust also depends on how you obtained the commit and any signature checks.
3. Digital Signatures and Message Authentication
Many digital-signature schemes process a digest of the message rather than the entire message. A digest is fixed size but not mathematically unique. HMAC combines a hash with a secret key to authenticate a message to parties that share that key — see What Is HMAC? and our HMAC Generator.
Salting: Why Two Identical Passwords Get Different Hashes
A plain hash has a weakness: identical inputs produce identical hashes, so attackers can precompute hashes of common passwords (rainbow tables). The defense is a salt — a unique random value added to each password before hashing:
hash("hunter2" + "a8F3z9") → unique hash
hash("hunter2" + "Qw71pK") → different hash
Now two users with the same password get different stored hashes, and precomputed tables become useless. Modern password hashers like bcrypt and Argon2 generate and embed salts automatically — use the Bcrypt Generator.
Hashing vs Encryption
| Hashing | Encryption | |
|---|---|---|
| Direction | One-way (irreversible) | Two-way (reversible with a key) |
| Purpose | Verify / protect | Conceal |
| Output | Fixed length | Varies with input |
| Example | SHA-256, bcrypt | AES, RSA |
Use hashing to verify data and store passwords; use encryption to keep data secret but recoverable. More in Hashing vs Encryption.
Secure vs Broken Algorithms
- ❌ MD5, SHA-1 — broken; don't use for security.
- ✅ SHA-256, SHA-512 — secure for integrity and signatures.
- ✅ bcrypt, scrypt, Argon2 — secure and deliberately slow, the right choice for passwords.
For accidental-change detection, a fast hash can be useful. For password storage, use a dedicated, tunable password hasher. For authenticity, use a signature or keyed MAC rather than an unkeyed digest. NIST FIPS 180-4 specifies the SHA family.
Frequently Asked Questions
What is hashing in cybersecurity? Computing a fixed-length digest that supports change detection and cryptographic protocols. Password storage requires a dedicated slow password hasher.
Why is hashing used for passwords? So systems never store the actual password. A breach exposes only hashes, which (with salting and a slow algorithm) are expensive to crack.
What is the difference between hashing and encryption? Hashing is one-way and used to verify data; encryption is reversible with a key and used to hide data so it can be read again later.
What is salting a hash? Adding a unique random value to each input before hashing, so identical passwords produce different hashes and rainbow-table attacks fail.
Which hash algorithms are secure? SHA-256 and SHA-512 for integrity; bcrypt, scrypt, or Argon2 for passwords. Avoid MD5 and SHA-1.
Related Reading
Hashing is a building block. Its security benefit depends on the full workflow: a slow salted password hasher for credentials, a trusted expected digest for integrity, or a signature or HMAC for authenticity.