In cryptography, a salt (also called a cryptographic salt) is a unique random value added to a secret before it is hashed or processed by a key derivation function, so that identical inputs produce different outputs. Salts are stored alongside the resulting hash and are not secret; their purpose is to make every hash individual rather than to hide information.
The main application is password hashing. Without a salt, two users with the same password receive the same stored hash, and attackers can crack millions of accounts at once with precomputed tables. A salt forces the attacker to attack each hash separately, which turns a single large computation into millions of independent ones. Not to be confused with the Salt configuration management tool, which is unrelated.
How a salt changes the hashing process
A salt is generated once per secret, at the moment the secret is set, using a cryptographically secure random number generator. The system combines the salt with the password, runs the combination through a password hashing function, and stores the salt, the hash and the algorithm parameters together, often in a single encoded string.
At login, the system reads the stored salt, combines it with the password the user just typed, repeats the same computation and compares the results in constant time. Because the salt is retrieved rather than regenerated, verification works without the salt ever being kept secret.
The table below shows the effect of salting on two accounts that share a password.
| Scenario | Stored values | Consequence for an attacker |
|---|---|---|
| Unsalted hash | Both accounts store the same hash | One crack reveals both; duplicates are visible |
| Shared global salt | Both accounts store the same hash | Precomputation still works per system |
| Unique per-user salt | Each account stores a different hash | Each hash must be attacked individually |
Attacks that salts defeat and attacks they do not
Salts neutralize precomputation and batch attacks but do not slow down an attack against a single hash. This distinction is the most important point to understand about salting, and it explains why salts must be combined with a deliberately slow hashing algorithm.
| Attack | Description | Effect of a unique salt |
|---|---|---|
| Rainbow table attack | Lookup in precomputed hash chains | Defeated, because tables would be needed per salt |
| Precomputed dictionary | Hashes of common passwords prepared in advance | Defeated for the same reason |
| Batch cracking | Testing each guess against all hashes at once | Defeated; each guess must be hashed per user |
| Duplicate detection | Spotting users who share a password | Defeated; hashes no longer match |
| Targeted brute force | Guessing one user’s password repeatedly | Not prevented; requires a slow algorithm |
Because modern graphics processors can compute billions of fast hashes per second, a salted SHA-256 hash of a weak password is still cracked quickly. Salting is therefore a necessary but insufficient measure on its own.
Salt length, generation and storage
A salt must be long enough and random enough that collisions are negligible. Current guidance, including NIST Special Publication 800-63B and the OWASP password storage recommendations, calls for at least 32 bits as an absolute minimum, while practical implementations use 16 bytes (128 bits) to make reuse of a salt across users effectively impossible.
| Parameter | Recommended value | Reason |
|---|---|---|
| Length | 16 bytes or more | Makes salt collisions statistically negligible |
| Source | Cryptographically secure random generator | Prevents predictable or repeated salts |
| Uniqueness | New salt for every password, including changes | Keeps old and new hashes unrelated |
| Storage | Next to the hash, in plain form | Needed for verification; secrecy is not required |
| Encoding | Standard format such as PHC string or modular crypt | Keeps algorithm, parameters and salt together |
Modern libraries for Argon2, bcrypt, scrypt and PBKDF2 generate and encode salts automatically. Developers should rely on these built-in mechanisms rather than constructing salts manually, because most salting errors arise in custom code.
Salt compared with nonce, pepper and initialization vector
A salt belongs to a group of auxiliary values that make cryptographic outputs unique, and the terms are often confused. The distinctions lie in secrecy, purpose and the primitive each value feeds.
| Value | Secret | Primary purpose | Used with |
|---|---|---|---|
| Salt | No | Individualize hashes and derived keys | Password hashing, key derivation |
| Pepper | Yes | Add a server-side secret to all hashes | Password hashing, kept outside the database |
| Cryptographic nonce | No | Ensure a value is never reused | Authenticated encryption, protocols |
| Initialization vector | No | Randomize the first cipher block | Block cipher modes such as CBC |
A pepper is often deployed alongside a salt, stored in a hardware security module or separate configuration, so that a stolen database alone does not allow offline cracking. In key derivation functions such as HKDF and PBKDF2, the salt also separates keys derived from the same input keying material.
Common salting mistakes
Most failures come from implementation shortcuts rather than weaknesses in the concept. Security reviews regularly find the following errors in legacy authentication code.
- Reusing one salt for all users, which restores the value of precomputed tables for that system.
- Deriving the salt from the username or email address, which makes it predictable and identical across systems.
- Using a short or low-entropy salt, for example a timestamp or a sequential counter.
- Pairing a salt with a fast hash such as MD5 or plain SHA-256 instead of a memory-hard or iterated algorithm.
- Treating the salt as a secret and building security assumptions on its confidentiality.
A non-technical view
Imagine every password being turned into a fingerprint before it is saved. Without a salt, the same password always leaves the same fingerprint, so a criminal who identifies one fingerprint can recognize it everywhere.
A salt is a random extra ingredient mixed in for each person. Two people with the same password now leave completely different fingerprints, and a criminal has to work on every account separately, which costs far more time.
A concrete example
An online retailer discovers that an old database backup containing 2 million customer password hashes has been exposed. The older part of the system stored unsalted SHA-1 hashes, and analysis shows that about 30 percent of them match entries in publicly available precomputed tables, so those passwords are effectively known.
The retailer forces password resets for all affected customers and migrates storage to Argon2id with a 16-byte random salt per user. Each new hash is now unique, duplicates are no longer visible, and an attacker who obtained the new database would have to run a slow, memory-hard computation separately for each of the 2 million accounts, turning a quick lookup into an impractical effort for strong passwords.