A password hash is a scrambled version of your password that a website stores instead of the real thing

When you create an account on a website, the site does not store your actual password in its database. Instead, it runs your password through a mathematical function called a hash function, which converts it into a long string of characters that looks like random gibberish. That scrambled string is what gets saved. The website never knows your real password — only you do.

The reason websites do this is security. If a hacker breaks into the website's database and steals the stored passwords, they get useless scrambled text instead of passwords they could use to log into your email, bank account, or other sites where you reuse that password. The hash cannot be reversed back into the original password, even by the website itself.

When you log in later, the website hashes whatever password you type and compares that new hash to the one stored in the database. If they match, you get in. If they do not match, the login fails. The website never actually compares your real password to anything — it only compares hashes.

Key Takeaways

  • A password hash is a one-way scrambled version of your password that websites store instead of the real password.
  • Hash functions are mathematical operations that always produce the same scrambled output for the same input, but cannot be reversed to recover the original password.
  • Even if a hacker steals a website's database of hashes, they cannot use those hashes to log in anywhere because the hashes are not the actual passwords.
  • When you log in, the website hashes what you type and compares it to the stored hash — it never stores or compares your real password.

How a hash function works

A hash function is a mathematical recipe that takes any input — your password, a sentence, a number — and produces a fixed-length output of scrambled characters. The same input always produces the same output. If you hash "mypassword123" a thousand times, you get the same hash every time.

But the process only works one direction. You cannot take the hash and work backward to figure out what the original password was. It is like putting a document through a shredder: you can shred the same document again and get the same pile of shreds, but you cannot reassemble the shreds back into the document.

Common hash functions used for passwords include bcrypt, Argon2, and PBKDF2. These are designed specifically to be slow — they take a fraction of a second to run, which is fine for you logging in once, but makes it extremely expensive for a hacker to guess millions of passwords by hashing them all and comparing to stolen hashes.

Why hashing is better than storing real passwords

If a website stored your actual password in plain text, a data breach would expose it directly. A hacker could then use that password to log into your email, your bank, your social media — anywhere you reused it. Millions of people reuse passwords across multiple sites, so one breach becomes a master key to many accounts.

With hashing, a stolen database of hashes is nearly worthless. The hacker has scrambled text that cannot be converted back into passwords. They could try to guess passwords by hashing common ones and comparing, but modern hash functions are designed to be slow enough that guessing millions of passwords would take years of computer time.

Hashing also protects you from the website's own employees. A customer service representative or database administrator at the company cannot see your password, because the website does not have it. They only have the hash, which tells them nothing about what you actually typed.

What "salt" means in password hashing

A salt is a random string of characters that the website adds to your password before hashing it. If your password is "mypassword123" and the salt is "x7k9m2", the website hashes "mypassword123x7k9m2" instead of just "mypassword123".

Salting prevents a specific attack: if two people use the same password, their hashes would normally be identical, which tells a hacker that they used the same password. By adding a different random salt to each password before hashing, the same password produces different hashes for different people. A hacker cannot tell that two accounts share a password just by looking at the hashes.

Salting also defeats rainbow tables — precomputed lists of common passwords and their hashes. A hacker could theoretically build a table of millions of hashed passwords and compare stolen hashes to it. But if each password has a unique salt, the precomputed table becomes useless, because the hashes in the table do not match the salted hashes in the stolen database.

The difference between hashing and encryption

Hashing and encryption are often confused, but they work in opposite directions. Encryption is reversible — you encrypt data with a key, and someone with the key can decrypt it back to the original. Hashing is one-way — you cannot reverse it, even if you have the hash function itself.

Websites use hashing for passwords because they do not need to recover the original password. They only need to verify that what you typed matches what was stored. Encryption would be the wrong tool for this job, because if the encryption key were stolen, a hacker could decrypt all the passwords.

Encryption is useful for other things — protecting data in transit between you and the website, or protecting sensitive files you want to store and later read. But for passwords, hashing is the standard because it is designed to be one-way.

What happens if you forget your password

Because the website does not store your real password, it cannot send it back to you if you forget it. Instead, the website sends you a link to reset your password. You click the link, type a new password, and the website hashes the new password and stores that hash.

This is actually a sign that the website is handling passwords correctly. If a website could send you your forgotten password in plain text, that would mean the website was storing your real password somewhere, which is a security failure. A legitimate password reset always requires you to create a new password, not recover the old one.

Common misunderstandings about password hashes

One common myth is that hashes can be "unhashed" with the right tool or password. They cannot. A hash function is mathematically one-way. No tool exists that can reverse a modern hash back into the original password, even if you have the hash function code itself.

Another misunderstanding is that all hashes are equally strong. They are not. Old hash functions like MD5 or SHA1 are fast, which makes them weak for passwords — a hacker with a powerful computer can guess billions of passwords per second. Modern functions like bcrypt and Argon2 are intentionally slow, making them much harder to crack. The website you use should be hashing passwords with a modern function, not an old one.

People also sometimes think that if a website is hacked, their password is definitely compromised. Not necessarily. If the website hashed passwords correctly, the hacker got hashes, not passwords. Whether the hacker can crack those hashes depends on how strong your password is and how strong the hash function is. A long, random password hashed with bcrypt is extremely difficult to crack, even if the hash is stolen.

Frequently Asked Questions

Can a website see my password when I type it?

No. When you type your password into the login form, your browser sends it to the website over an encrypted connection (HTTPS). The website receives it, hashes it when ready, and compares the hash to the stored hash. The website never stores or displays your actual password. The only place your real password exists is in your own memory and in your password manager if you use one.

If my password hash is stolen, can someone use it to log into my account?

No. A hash is not a password — it is a scrambled version of a password. To log in, someone would need the actual password, not the hash. They could try to guess passwords and hash them to see if any match the stolen hash, but modern hash functions are designed to make this extremely slow and expensive.

Why do some websites ask me to change my password after a breach?

If a website was hacked and passwords were stored with a weak hash function, the hacker might be able to crack many of the hashes and recover real passwords. In that case, changing your password makes sense. If the website used a strong hash function, changing your password is less urgent, but still a reasonable precaution if you reused that password elsewhere.

Is a longer password always harder to crack from a hash?

Yes. A longer password has more possible combinations, so it takes longer to guess by hashing common passwords and comparing. A 20-character random password is vastly harder to crack than an 8-character one, even if both are hashed with the same function. This is why password managers that generate long random passwords are so effective.

Do I need to know what hash function a website uses?

You do not need to know the specific function, but you can ask. A website that is transparent about using bcrypt or Argon2 is a good sign. A website that does not answer the question or uses an old function like MD5 is a red flag. Most people do not have the technical knowledge to evaluate this, so focusing on using a unique, strong password is more practical.