Salt · cryptography

Also known as: cryptographic salt

On this page 7

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.

ScenarioStored valuesConsequence for an attacker
Unsalted hashBoth accounts store the same hashOne crack reveals both; duplicates are visible
Shared global saltBoth accounts store the same hashPrecomputation still works per system
Unique per-user saltEach account stores a different hashEach hash must be attacked individually
Effect of salting on identical passwords

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.

AttackDescriptionEffect of a unique salt
Rainbow table attackLookup in precomputed hash chainsDefeated, because tables would be needed per salt
Precomputed dictionaryHashes of common passwords prepared in advanceDefeated for the same reason
Batch crackingTesting each guess against all hashes at onceDefeated; each guess must be hashed per user
Duplicate detectionSpotting users who share a passwordDefeated; hashes no longer match
Targeted brute forceGuessing one user’s password repeatedlyNot prevented; requires a slow algorithm
Attacks and the protection a salt provides

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.

ParameterRecommended valueReason
Length16 bytes or moreMakes salt collisions statistically negligible
SourceCryptographically secure random generatorPrevents predictable or repeated salts
UniquenessNew salt for every password, including changesKeeps old and new hashes unrelated
StorageNext to the hash, in plain formNeeded for verification; secrecy is not required
EncodingStandard format such as PHC string or modular cryptKeeps algorithm, parameters and salt together
Practical salt parameters

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.

ValueSecretPrimary purposeUsed with
SaltNoIndividualize hashes and derived keysPassword hashing, key derivation
PepperYesAdd a server-side secret to all hashesPassword hashing, kept outside the database
Cryptographic nonceNoEnsure a value is never reusedAuthenticated encryption, protocols
Initialization vectorNoRandomize the first cipher blockBlock cipher modes such as CBC
Salt and related cryptographic values

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.