What hashing does to your password

When you create a password at a website or app, that site does not store the password itself. Instead, it runs your password through a hashing function — a mathematical process that turns your password into a fixed-length string of characters that looks like gibberish. That gibberish is what gets saved in the database.

The key difference: hashing is one-way. If someone steals the database, they see the hashed version, not your actual password. They cannot reverse the hash to get the original password back. When you log in later, the site hashes what you type, compares it to the stored hash, and if they match, you are in.

This matters because databases get breached. A hashing function ensures that even when they do, your password stays secret. The attacker gets a list of hashes, not passwords.

Key Takeaways

  • Hashing converts your password into a one-way mathematical output that cannot be reversed to reveal the original password.
  • The same password always produces the same hash, so the site can verify you by comparing what you type to what is stored.
  • A strong hashing function makes it computationally impractical to guess passwords by testing millions of hashes per second.
  • Modern password hashing uses additional techniques like salting and stretching to slow down attackers even further.

Why one-way matters

A one-way function is the whole point. Encryption works both ways — you encrypt data and decrypt it with a key. Hashing does not work that way. There is no key that turns the hash back into the password. The math is designed so that reversing it is harder than guessing every possible password.

This is why a site administrator cannot tell you your password if you forget it. They do not know it. They can only reset it to something new, hash that new password, and store the hash. If they claim they can send you your old password, that site is not hashing passwords — it is storing them in plain text, which is a serious security failure.

How the same password always produces the same hash

Hashing functions are deterministic. Feed the same input in, and you get the same output every time. This is what makes verification work. When you log in, the site hashes what you typed and compares it to the stored hash. If they match, the password is correct.

But this creates a problem: if two people use the same password, their hashes are identical. An attacker who steals the database can see that thousands of accounts share the same hash, meaning thousands of people use the same password. They can then focus their guessing effort on that one hash.

This is where salting comes in. A salt is a random string added to your password before hashing. Even if two people use the password "password123", the site adds a different random salt to each one before hashing. Now the hashes are different, and the attacker cannot tell that both accounts use the same password.

What makes a hashing function strong

A strong hashing function for passwords has two properties: it produces a different output for even tiny changes to the input, and it is slow to compute. The slowness is intentional.

If a hashing function were fast, an attacker with a stolen database could test millions of guesses per second. They would hash "password", "password1", "password2", and so on, comparing each hash to the stolen ones until they found matches. A function that takes a full second to compute one hash makes this attack impractical — testing a million guesses would take eleven days.

Common hashing functions for passwords include bcrypt, scrypt, and Argon2. These are deliberately slow. Older functions like MD5 and SHA-1 were designed for speed and are no longer considered safe for passwords, because modern computers can test billions of hashes per second.

Salting and stretching explained

A salt is a random value added to your password before hashing. It ensures that the same password produces different hashes for different accounts. Salts are stored alongside the hash in the database — they do not need to be secret, because their job is to prevent attackers from using precomputed tables of common passwords and their hashes.

An attacker could theoretically precompute hashes for every common password and store them in a lookup table called a rainbow table. When they steal a database, they just look up each hash in their table. Salting defeats this: because each account has a different salt, the attacker would need a separate rainbow table for each salt, which is impractical.

Stretching means running the hash function multiple times on the same input. If bcrypt hashes your password 2^12 times (4,096 iterations), an attacker has to do 4,096 times as much work to test each guess. Modern implementations use even higher iteration counts or adaptive functions that increase the cost over time as computers get faster.

What happens when you log in

When you enter your password at login, the site takes what you typed, adds the salt that was stored with your account, hashes it using the same function and iteration count, and compares the result to the stored hash. If they match exactly, you are authenticated.

The site never sees your actual password during this process. It only sees the hash you just generated. If someone intercepts your password in transit — over an unencrypted connection, for example — they get the password itself, which is why sites use HTTPS to encrypt the connection. But once the password reaches the server and gets hashed, the plain text is discarded.

Why this matters for you

Understanding hashing explains why a strong password matters even at sites with good security. A hashing function slows down attackers, but it does not stop them. If your password is "123456" or "password", an attacker can test those guesses quickly even against a slow hash function. A long, random password — one that is not in any dictionary — takes far longer to guess.

It also explains why you should use different passwords at different sites. If one site is breached and the attacker cracks some of the weaker passwords through brute force, they will try those same passwords at other sites. A unique password at each site means a breach at one place does not compromise your accounts elsewhere.

Frequently Asked Questions

Can a hashed password ever be unhashed?

No. A proper hashing function is mathematically one-way. An attacker cannot reverse a hash to get the password. They can only guess passwords, hash them, and compare the results. This is why strong hashing functions are slow — they make guessing impractical.

Why do sites ask me to reset my password instead of sending the old one?

Because the site does not have your old password. It only has the hash. A site that can send you your password is storing it in plain text, which means a breach exposes your actual password, not just a hash. A reset is the only option when passwords are hashed correctly.

Does hashing protect my password if I use a weak one?

Hashing slows down attackers, but a weak password like "password" or "123456" can still be cracked through brute force, even against a slow hash function. Hashing protects you from rainbow tables and precomputed attacks, but not from determined guessing. A long, random password is still essential.

What is the difference between hashing and encryption?

Encryption is two-way: you encrypt data with a key and decrypt it with the same key to get the original back. Hashing is one-way: you cannot reverse it. Passwords use hashing because the site never needs to recover the original password — it only needs to verify that what you typed matches what is stored.

If the salt is stored in the database, why does it matter?

The salt does not need to be secret because its job is not to hide the hash — it is to prevent attackers from using precomputed tables. Without a salt, an attacker can build a rainbow table for common passwords once and use it against any breached database. With a salt, they would need a separate table for each salt, which is impractical.