Explain the concept of Salt in password hashing.
Updated Apr 28, 2026
Short answer
A salt is a random value added to a password before hashing to make each password hash unique, even when users have the same password. It protects against attacks that use precomputed hash databases, such as rainbow tables, and makes large-scale password cracking more difficult. Salts are stored alongside password hashes because they are not meant to be secret.
Deep explanation
Password hashing is a security technique used to store passwords safely without storing the original password. Instead of saving:
User Password:MyPassword123A system stores a hash:
Password Hash:ef92b778bafe771e89245b89ecbc08a44a4e166c06687...When the user logs in, the system hashes the entered password and compares it with the stored hash.
However, storing only a normal hash creates a problem.
---
The Problem Without a Salt
Hash functions always produce the same output for the same input.
Example:
Hash("password123")
=
ef92b778bafe771e89245b89ecbc08a44a4e166c06687...If many users choose the same password:
User A:password123
User B:password123
User C:password123Their stored hashes will be identical:
User A → ef92b778...User B → ef92b778...User C → ef92b778...An attacker who sees identical hashes can determine that multiple accounts use the same password.
Additionally, attackers can use precomputed tables containing common passwords and their hashes.
Example:
password123 → ef92b778...admin123 → 0192023a...qwerty → 65e84be3...If a stolen database contains matching hashes, attackers can quickly discover passwords.
---
How Salt Works
A salt is a random value generated for each password before hashing.
Instead of hashing:
PasswordThe system hashes:
Password + SaltExample:
Password:
password123
Salt:
a8F92kLm
Hash input:
password123a8F92kLmThe result:
Hash:
8d72f91c4b2a...Another user with the same password receives a different salt:
Password:
password123
Salt:
Z91xPq44
Hash input:
password123Z91xPq44Result:
Hash:
b72ac9018d4e...Although the passwords are the same, the hashes are different.
---
Salt Storage
A salt does not need to be hidden.
A database usually stores:
| Username | Salt | Password Hash |
|---|---|---|
| Alice | a8F92kLm | 8d72f91c4b2a... |
| Bob | Z91xPq44 | b72ac9018d4e... |
During login:
- The application retrieves the user's salt.
- It combines the entered password with that salt.
- It hashes the result.
- It compares the generated hash with the stored hash.
Example:
Entered Password:password123
Stored Salt:a8F92kLm
Hash:
Hash(password123 + a8F92kLm)
Compare with stored hash---
Benefits of Using Salts
Prevents Identical Passwords From Having Identical Hashes
Without salt:
password123 → hash123password123 → hash123With salt:
password123 + saltA → hashApassword123 + saltB → hashB---
Protects Against Rainbow Tables
A rainbow table is a precomputed list of passwords and their hashes.
Without salts:
Password → Hash
password123 → abc123Attackers can look up the hash directly.
With salts:
Password + Random Salt → HashEvery possible salt creates a different hash, making precomputed tables impractical.
---
Increases Attack Cost
If an attacker steals a database containing password hashes, they must calculate guesses separately for each user because every password has a different salt.
Without salts:
Try password123 onceCompare against millions of usersWith salts:
Try password123 + User1 saltTry password123 + User2 saltTry password123 + User3 salt---
Salt vs Hashing vs Encryption
| Concept | Purpose | Reversible |
|---|---|---|
| Hashing | Store passwords securely | No |
| Salt | Make password hashes unique | Not applicable |
| Encryption | Protect data confidentiality | Yes with key |
Passwords should generally be hashed, not encrypted, because the original password should never need to be recovered.
---
Password Hashing Algorithms With Salt Support
Modern password storage should use dedicated password hashing algorithms that include salt handling.
Common choices:
- bcrypt
- Argon2
- scrypt
- PBKDF2
Example:
bcrypt(password, salt)
↓
stored hashThese algorithms are intentionally slow and resource-intensive to make brute-force attacks harder.
---
Real-world example
A website stores user passwords.
A user registers:
Username:john@example.com
Password:SecurePassword123The application generates a random salt:
Salt:9xK4mP7qIt hashes:
SecurePassword1239xK4mP7qThe database stores:
Username:john@example.com
Salt:9xK4mP7q
Hash:$2b$12$LQv3c1y9...During login:
import bcrypt
password = b"SecurePassword123"
stored_hash = b"$2b$12$LQv3c1y9..."
if bcrypt.checkpw(password, stored_hash): print("Login successful")The system verifies the password without ever storing the original password.
Common mistakes
- * Storing plain text passwords instead of hashes.
- * Using the same salt for every user.
- * Treating a salt as a secret key.
- * Using fast general-purpose hashes like SHA-256 directly for password storage.
- * Reusing predictable or fixed salts.
- * Believing that adding a salt makes weak passwords impossible to crack.
- * Storing only the hash and losing the salt required for verification.
- * Generating salts manually instead of using secure random functions.
- * Encrypting passwords when hashing is the correct approach.
Follow-up questions
- Why does every user need a different salt?
- Should a salt be kept secret?
- Why is hashing preferred over encryption for passwords?
- What is the difference between a salt and a pepper?
- Why are bcrypt and Argon2 preferred for password hashing?
- Can a salted password hash still be cracked?