Free online courseInteractive · No sign-up · Works offline once loaded

Hashing & password security

Why a hash can’t be decrypted, how attackers still crack millions of passwords, and how salt, bcrypt and Argon2 stop them. With live demos that run in your browser.

  • Beginner
  • 7 chapters
  • 24 interactive lessons
  • About 31 minutes
  • English
  • Updated November 2026
Start the course 24 lessons · about 31 min · free
What a hash is Lesson 1 of 24

Chapter 1: What a hash is

Lesson 1.1 · What a hash is

A fingerprint for any data

A hash function reads any input and produces a short value of fixed length: the hash. Think of it as a fingerprint of the data.

The same input always gives the same hash, on every computer. That's why hashes are used to check downloads, find duplicate files and store passwords.

Try itType anything: one word, nothing at all, or a whole paragraph. Watch the length of the hashes.

MD5 always 32 hex characters
5d41402abc4b2a76b9719d911017c592
SHA-256 always 64 hex characters
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Computed in your browser. Nothing you type leaves this page.

Lesson 1.2 · What a hash is

One letter, a whole new hash

Change a single character and the hash changes completely. About half of the 256 bits flip, and you can't see any pattern.

This is the avalanche effect. It means two hashes tell you only one thing: same or different. They never tell you how close two inputs were.

Try itChange one letter in B, or press the button. Count the flipped bits.

SHA-256 of A

SHA-256 of B

Lesson 1.3 · What a hash is

Any length in, the same length out

One letter or a 4 GB film: SHA-256 always returns 256 bits, written as 64 hex characters.

So in theory many inputs share each hash. Such a pair is a collision. For SHA-256 nobody has ever found one: there are 2256 possible values, a number with 78 digits. For MD5 and SHA-1 researchers have built collisions on purpose.

(empty)HihiThe quick brown fox… SHA-256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8553639efcd08abb273b1619e82e78c29a7df02c1051b1820e99fc395dcaa3326b88f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592 always 64 hex characters = 256 bits
2256possible SHA-256 values
2004first MD5 collision
2017first SHA-1 collision
Lesson 1.4 · What a hash is

Encoding, encryption or hashing?

Three words that get mixed up all the time:

  • Encoding changes the format. Anyone can reverse it, no key needed. Example: Base64.
  • Encryption locks data with a key. With the key you get it back. Example: AES.
  • Hashing makes a fingerprint. There is no key and no way back.
Example 1 of 6

Chapter 2: Why you can’t decrypt a hash

Lesson 2.1 · Why you can’t decrypt a hash

A hash throws information away

Here is a toy hash: add up the letters (A = 1 … Z = 26) and keep the last two digits.

“cat” gives 24. So do many other words. From 24 alone nobody can tell which word it was: the information is gone.

Real hashes mix the bits far more thoroughly and have 2256 results instead of 100. But they are just as impossible to run backwards.

Try itType a word and see which other words give the same toy hash.

c 3 + a 1 + t 20 = 24

Toy hash24
Other words with toy hash 24

Only 100 possible results, so collisions are everywhere. That's what makes it a toy.

Lesson 2.2 · Why you can’t decrypt a hash

How “MD5 decrypt” websites really work

They don't decrypt anything. They hashed long lists of known passwords in advance and look your hash up in that table.

If the original was on the list, they “find” it. If not, they are stuck. This page does the same with 11,781 common passwords, PINs and years, right in your browser.

Try itTry both examples, or paste an MD5 hash of your own.

The list is part of this page. Nothing is sent anywhere.

Lesson 2.3 · Why you can’t decrypt a hash

Guessing, billions of times per second

An attacker with a hash and no table simply guesses: hash a candidate, compare, next.

MD5 and SHA-256 are built to be fast, which is great for checking files and terrible for passwords. One gaming graphics card computes about 164 billion MD5 hashes per second.

Your device, this tabmeasuring…MD5 guesses per second
One RTX 4090 graphics card164 billionMD5 guesses per second
Try every password of …PossibilitiesOne RTX 4090
6 lowercase letters308,915,776less than a second
8 lowercase letters208,827,064,576about 1 second
8 letters and digits218,340,105,584,896about 22 minutes
8 of any keyboard character6.6 × 1015about 11 hours
12 of any keyboard character5.4 × 1023about 100,000 years
5 random words from a 7,776-word list2.8 × 1019about 5 years

GPU speed: hashcat benchmark, August 2025. Your speed is measured right now, with plain JavaScript.

Lesson 2.4 · Why you can’t decrypt a hash

The honest answer

So what can you really do with a hash you found?

  • Check if it's a known password. That's all any “decrypter” does.
  • Forgot your own password? Use “forgot password”. The service can't read it either.
  • Building a login? You never need to decrypt. Hash what the user types and compare.
What can you find out?

An old database contains 5f4dcc3b5aa765d61d8327deb882cf99 for one user. It's an MD5 hash.

Chapter 3: Passwords in a database

Lesson 3.1 · Passwords in a database

How a login checks your password

A good website never stores your password. It stores a hash of it.

When you log in, it hashes what you typed and compares that with the stored hash. Match: you're in. The site never needs to know, or decrypt, your password.

For now we use plain SHA-256. In chapter 4 you will see why real systems use something slower.

Try itLog in as maya. Try a wrong password first, then blue-otter-42.

Lesson 3.2 · Passwords in a database

A leaked table of plain hashes

Here is a leaked table with unsalted MD5 hashes. Two problems jump out:

  • Same password, same hash. Three users share one value. It must be a popular password.
  • One table cracks everyone. A list of common passwords, hashed once, breaks most rows at once.

In 2012 LinkedIn lost about 117 million unsalted SHA-1 hashes like this.

Try itSpot the identical hashes. Then run the list of common passwords.

userpassword_md5cracked
anae10adc3949ba59abbe56e057f20f883e–
ben0571749e2ac330a7455809c6b0e7af90–
chene10adc3949ba59abbe56e057f20f883e–
dana11a67cb4fdf932991d9ffe5d6dd0d5a5–
eli3fc0a7acf087f549ac2b266baf94b8b1–
femi8621ffdbc5698829397d97767ac13db3–
guse10adc3949ba59abbe56e057f20f883e–
hana2e30e9560875b01d1355c8d22722b0c7–

Highlighted rows have the same hash.

Lesson 3.3 · Passwords in a database

Salt: a random value for every user

A salt is a random value, different for every user, mixed into the password before hashing. It is stored right next to the hash. It is not a secret.

Same password, different hashes. A table built in advance is useless now: the attacker has to start over for every single user.

But look: weak passwords still fall when guessed one by one. Salt stops the shortcuts, not the guessing.

Try itTry the precomputed list first. Then guess user by user.

usersaltmd5(salt + password)cracked
ana7f9b05389e06c750d63995460e278a2e317b68b5cd8d7c3b–
ben470162841f1a69ba52e48aa02b85c3977e488255d6a54f08–
chen144c6e78ef8cff57372cdde26d4b9ccb4add16dd3f263141–
dana41611ec5cfc4d72bdf97e39c3d10538105399b5a254de83b–
eli78837354428b2283d987c0f4762b818bd3ab5653a549a427–
femie28fceb0d4866de966d3e3d21cf3213605b644d760b409e8–
gus0547f0737c6ade41868c4414c304964114e727d694d1ae5a–
hana2e2d4b6b855e84abed064b833d3bed54073e16432e3c718c–

No two hashes are the same, even though ana, chen and gus still share a password.

Lesson 3.4 · Passwords in a database

Fast is the problem

SHA-256 was built to be fast: it checks a big download in a moment. For passwords that speed helps the attacker.

Password hashes like bcrypt are slow on purpose. A login that takes a tenth of a second doesn't bother you. An attacker who wants to try billions of passwords is stopped in his tracks.

Try itStart the race. Both run on your device for one second each.

SHA-256
–
bcrypt, cost 10
–

Hashes per second on your device. The bar length uses a log scale, otherwise bcrypt would be invisible.

Press start to measure.

Chapter 4: Password hashing done right

Lesson 4.1 · Password hashing done right

bcrypt: slow on purpose

bcrypt has a cost factor. Each step up doubles the work: cost 12 is four times slower than cost 10.

As computers get faster, you simply raise the cost. PHP uses 12 by default since version 8.4.

Every run picks a new random salt, so the same password gives a different hash each time. That's intended.

Try itHash with cost 10, then 11, then 12. Watch the time double.

–

    Lesson 4.2 · Password hashing done right

    Reading a bcrypt hash

    A bcrypt hash is one string of 60 characters. It holds everything needed to check a password later: the version, the cost, the salt and the result.

    You store it as it is. No extra column for the salt, nothing to keep secret.

    Try itTap each part of the hash.

    Tap a part

    This is a real bcrypt hash of “blue-otter-42” with cost 12, made by the build of this page.

    Lesson 4.3 · Password hashing done right

    Memory-hard: scrypt and Argon2

    Graphics cards are fast because they run thousands of small cores side by side. Each core has very little memory.

    scrypt and Argon2 make every guess need a lot of memory. With Argon2id at 19 MiB per guess, an RTX 4090 can only work on about 1,200 guesses at a time, although it has 16,384 cores.

    Argon2 won the Password Hashing Competition in 2015.

    Try itRun Argon2id with the settings OWASP recommends.

    SHA-256 every core guesses Argon2id, 19 MiB each memory runs out first 16,384 cores at work 24 GB ÷ 19 MiB ≈ 1,200 at a time

    m = 19 MiB, t = 2, p = 1, the OWASP minimum.

    Lesson 4.4 · Password hashing done right

    Which one should you use?

    The OWASP cheat sheet recommends, in this order:

    1. Argon2id for new systems
    2. scrypt if Argon2id isn't available
    3. bcrypt for older systems, cost 10 or more
    4. PBKDF2 only where FIPS-140 is required

    Don't build it yourself. Use the ready-made functions of your language. They create the salt for you.

    // bcrypt by default (cost 12 since PHP 8.4)
    $hash = password_hash($password, PASSWORD_DEFAULT);
    
    // at login
    if (password_verify($password, $hash)) {
        // correct; upgrade old hashes on the fly
        if (password_needs_rehash($hash, PASSWORD_DEFAULT)) {
            $hash = password_hash($password, PASSWORD_DEFAULT);
        }
    }
    
    // Argon2id, if PHP was built with it
    $hash = password_hash($password, PASSWORD_ARGON2ID);
    Lesson 4.5 · Password hashing done right

    Fine or a mistake?

    These all come up in real code reviews. Decide for each one: is it fine, or a mistake?

    Tip: anything homemade, fast or reversible is a mistake.

    Case 1 of 7

    Chapter 5: HMAC: a hash with a key

    Lesson 5.1 · HMAC: a hash with a key

    Anyone can recompute a plain hash

    A hash sent along with a message catches accidents. It doesn't stop an attacker: he changes the message and computes a new hash.

    An HMAC mixes a secret key into the hash. Without the key, nobody can make a matching tag.

    Try itLet the attacker change the message. Then switch to HMAC and try again.

    1. Sender

      Pay 10 EUR to Alice

      83a21768ead5f1f86d1d5a60c59dd955821a76e5256b0881e92b39b29011ed40
    2. On the way

      Untouched

    3. Receiver

      Recomputes the tag and compares.

    Lesson 5.2 · HMAC: a hash with a key

    How HMAC mixes in the key

    HMAC hashes twice. First the key (mixed with a fixed pattern called ipad) plus the message. Then the key again (mixed with opad) plus that first result.

    Why not just sha256(key + message)? With SHA-256 an attacker could add text to the message and compute a valid hash without the key: a length-extension attack. The double step prevents it.

    Try itChange the key or the message and watch both steps.

    key ⊕ ipadmessage SHA-256inner key ⊕ opadinner SHA-256HMAC

    innera2e485863d27f9d864ac8d802432a1ed477d8c4c6f349d16d4e7e917c629cad7

    HMAC-SHA2565bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843

    This is test case 2 of RFC 4231. Every correct HMAC-SHA256 gives exactly this result.

    Lesson 5.3 · HMAC: a hash with a key

    Where you meet HMAC

    HMAC works quietly in many places you use every day.

    It can't be decrypted either. But a short key can be guessed like a password. Use at least 32 random bytes, and compare tags with a constant-time function such as hash_equals() in PHP or hmac.compare_digest() in Python.

    1. 1
      WebhooksGitHub signs every delivery: X-Hub-Signature-256: sha256=… Your server recomputes it with the shared secret.
    2. 2
      JSON Web TokensA JWT with “alg”: “HS256” is signed with HMAC-SHA256. A weak secret lets attackers forge tokens.
    3. 3
      API requestsMany cloud APIs sign each request with HMAC, so a stolen request can’t be changed.
    4. 4
      Authenticator appsThe six-digit codes (TOTP, RFC 6238) are an HMAC of the current time, cut down to six digits.

    Chapter 6: Your own passwords

    Lesson 6.1 · Your own passwords

    Length beats symbols

    Every extra character multiplies the work for an attacker. Symbols help a little; length helps a lot.

    And the website matters: the same password survives seconds with MD5 and centuries with bcrypt.

    These are upper limits for randomly chosen passwords. Human patterns fall much faster.

    Try itCompare the examples, then try a pattern of your own (not your real password).

    Length
    9 characters
    Character pool
    95
    Stored with MD5, one RTX 4090
    –
    Stored with bcrypt cost 12, same card
    –

    About 164 billion MD5 and about 1,563 bcrypt (cost 12) guesses per second, on average half the possibilities tried. Nothing you type leaves this page.

    Lesson 6.2 · Your own passwords

    Check for leaks without telling anyone

    Have I Been Pwned can tell you if a password appeared in a data breach, without learning the password.

    Your browser hashes it with SHA-1 and sends only the first 5 characters. The service returns every leaked hash starting with them, often hundreds, and your browser compares the rest. This is called k-anonymity.

    Try itType a password and see the only part that would be sent.

    21BD12DC183F740EE76F27B78EB39C8AD972A757

    Sent to the service (5 of 40 characters)Stays in your browser
    In the answer, your browser looks for this line

    2DC183F740EE76F27B78EB39C8AD972A757:times seen

    This page sends nothing. To run the real check, use haveibeenpwned.com.

    Lesson 6.3 · Your own passwords

    Four habits that protect you

    You can't control how a website stores your password. You can make sure one leak never opens your other accounts.

    • A password managerA different, random password for every site. You only remember one.
    • One long passphraseFor the manager itself: four or five random words you chose yourself.
    • A second factorAn authenticator app, a security key or a passkey wherever it’s offered.
    • Change it after a leakNot on a schedule, but when a service tells you it was breached.

    Chapter 7: Final check

    Lesson 7.1 · Final check

    Ready to explain it to someone else?

    Nine questions on everything in this course. Try as often as you like.

    Question 1 of 90 correct

    Course complete

    Almost there

    You have seen 0 of 24 lessons.

    Put your name on the certificate, then print it or save it as a PDF. Your name stays in this browser.

    encode-decode Academy

    Certificate of completion

    Your name

    has completed the free online course

    Hashing & password security

    7 chapters · 24 interactive lessons · about 31 minutes

    encode-decode.com/academy/hashing-passwords/

    Course notes

    The course as text

    Everything from the lessons in 7 short chapters, to read or to look something up later.

    Chapter 1

    What a hash is

    A hash function turns any input into a short, fixed-length value called a hash or digest. The same input always gives the same hash. The word hello has the MD5 hash 5d41402abc4b2a76b9719d911017c592 and the SHA-256 hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824, on every computer, in every programming language. MD5 always gives 32 hex characters (128 bits), SHA-256 always 64 (256 bits), no matter if you hash one letter or a whole film.

    Good hash functions have an avalanche effect: change one character and about half of the output bits flip. The new hash looks completely unrelated to the old one, so you can't tell from two hashes how similar their inputs were.

    Because the output has a fixed length but the input can be anything, many inputs must share each hash. Such a pair is called a collision. For a good hash it is still practically impossible to find one: SHA-256 has 2256 possible values. For MD5 (2004) and SHA-1 (2017) researchers have built collisions on purpose, so they are no longer safe where an attacker could swap data.

    Hashing is not encryption and not encoding. Base64 is an encoding: anyone can turn it back. Encryption, like AES, can be reversed with the right key. A hash has no key and no way back. More in the glossary: hashing vs encryption.

    Open the lessons of chapter 1 →
    Chapter 2

    Why you can’t decrypt a hash

    A hash can't be decrypted, because it doesn't contain the input. It is a short summary, and most of the information is thrown away on purpose. Our toy hash in the lessons adds up the letters of a word and keeps the last two digits. From the result 24 you can't tell if the word was “cat” or one of thousands of others. Real hash functions work on bits, with far more mixing and 2256 possible results instead of 100, but the principle is the same.

    So how do websites that promise “MD5 decrypt” work? They hashed huge lists of known passwords and words in advance and look your hash up in that table. If the original was on their list, they find it. If it wasn't, they can't. Our MD5 password check does the same in your browser with about 11,781 common passwords.

    The other way is guessing: hash every candidate and compare. Because MD5 and SHA-256 are built to be fast, this is very quick. One gaming graphics card (an Nvidia RTX 4090) computes about 164 billion MD5 hashes per second, according to hashcat benchmarks. Every password of 8 lowercase letters is tried in about 1 second. Every 8-character password using any keyboard character takes about 11 hours.

    So the honest answer to “can I decrypt this hash?” is: no, but you can check whether it is the hash of a known or weak password. If you forgot your own password, use the “forgot password” link of the service. If you are a developer, you never need to decrypt: hash what the user types and compare. More in the glossary: Can you decrypt a hash?

    Open the lessons of chapter 2 →
    Chapter 3

    Passwords in a database

    A website should never store your password itself. If the database leaks, every account is open, and because people reuse passwords, many other accounts too. Instead the site stores a hash. When you log in, it hashes what you typed and compares the result with the stored hash. If they match, the password was right. The site never needs to know your password.

    A plain, unsalted hash is not enough. Everyone with the same password gets the same hash, so an attacker sees at once which passwords are common, and one lookup table cracks all of them. That is what happened to LinkedIn: in 2012 attackers stole about 117 million unsalted SHA-1 password hashes, and a large share was cracked quickly.

    A salt fixes this. It is a random value, different for every user, that is mixed into the password before hashing and stored next to the hash. Same password, different hashes. Tables built in advance become useless, and the attacker has to guess for each user separately. The salt is not secret. It doesn't make a weak password strong; it only stops the shortcuts.

    The bigger problem remains speed. SHA-256 is designed to be fast. In the race on this page, SHA-256 is many thousands of times faster than bcrypt. For files that's great. For passwords it means billions of guesses per second.

    Open the lessons of chapter 3 →
    Chapter 4

    Password hashing done right

    Password hashing functions are slow on purpose, and you can choose how slow. bcrypt (1999) has a cost factor: each step up doubles the work. Cost 12 means 212 rounds of its expensive key setup. Since PHP 8.4, password_hash() uses cost 12 by default. A bcrypt hash such as $2a$12$Ax/Tcn9C4O2xUF0gv8uPLeYDbEv/SW1MT9ri8zua9hcD4Cwf8c/kO contains everything needed to check a password later: the version, the cost, the 22-character salt and the 31-character hash. You store this one string.

    Graphics cards are fast because they run thousands of small cores at once. scrypt and Argon2 are also memory-hard: every guess needs a lot of memory. With Argon2id at 19 MiB per guess, the 24 GB of an RTX 4090 hold only about 1,200 guesses at a time, although the card has 16,384 cores. Argon2 won the Password Hashing Competition in 2015 and is standardised as RFC 9106.

    The OWASP Password Storage Cheat Sheet recommends, in this order: Argon2id with at least 19 MiB of memory, 2 iterations and 1 degree of parallelism; scrypt with N = 217, r = 8, p = 1; bcrypt with a cost of at least 10 for older systems; and PBKDF2-HMAC-SHA256 with 600,000 iterations where FIPS-140 compliance is needed. Use your language's ready-made functions, for example password_hash() and password_verify() in PHP. They create the salt for you.

    Common mistakes: hashing twice with MD5, building your own sha256(salt + password), encrypting passwords instead of hashing them, limiting the length to a few characters, and forgetting that bcrypt only uses the first 72 bytes of a password.

    Open the lessons of chapter 4 →
    Chapter 5

    HMAC: a hash with a key

    A plain hash proves that data hasn't changed by accident. It doesn't protect against an attacker, because anyone can compute a new hash for changed data. If a message “Pay 10 EUR to Alice” is sent together with its SHA-256 hash, an attacker can change it to “Pay 1000 EUR to Mallory” and simply send the new SHA-256 along.

    An HMAC (hash-based message authentication code, RFC 2104 from 1997) mixes a secret key into the hash. Only someone who knows the key can make a valid tag. The receiver recomputes the HMAC with the same key and compares. HMAC hashes twice: first the key combined with the inner padding and the message, then the key combined with the outer padding and that inner result.

    Why not simply sha256(key + message)? SHA-256, SHA-1 and MD5 are open to a length-extension attack: from the hash of key + message, an attacker can compute a valid hash for a longer message without knowing the key. HMAC's double structure prevents this.

    You meet HMAC in webhooks (GitHub signs every delivery in the X-Hub-Signature-256 header with HMAC-SHA256), in JSON Web Tokens with HS256, in API request signing and in the six-digit codes of authenticator apps (TOTP, RFC 6238). An HMAC can't be decrypted either. But a short or guessable key can be guessed, so use at least 32 random bytes, and compare tags with a constant-time function.

    Open the lessons of chapter 5 →
    Chapter 6

    Your own passwords

    How long a password survives depends on two things: how it was chosen, and how the website stores it. For a randomly chosen password, every extra character multiplies the work. Length beats symbols: P@ssw0rd! looks complex, but it is a common word with predictable swaps, and cracking tools try exactly those first. Four or five random words are long, easy to type and hard to guess. Pick them yourself at random: famous examples from comics and articles are on every cracking list.

    The US standard NIST SP 800-63B-4 (2025) asks websites for at least 15 characters when a password is the only login factor, to allow at least 64, not to force mixes of character types, and to check new passwords against lists of breached passwords.

    Have I Been Pwned offers such a check without learning your password. Your browser computes the SHA-1 hash of the password and sends only the first 5 hex characters. The service returns all known leaked hashes that start with them, often several hundred, and your browser compares the rest. This model is called k-anonymity. This course sends nothing; it only shows you what would be sent.

    The habits that matter most: a password manager with a different password for every site, a long passphrase for the manager itself, and a second factor or a passkey wherever it is offered.

    Open the lessons of chapter 6 →
    Chapter 7

    Final check

    That's the whole course. To try the ideas on real values, every hash page has a password check, a comparison field and an avalanche demo, for example MD5, SHA-256 and SHA-1. To find out what kind of hash you have, use Identify.

    Open the lessons of chapter 7 →
    Glossary

    Words you will meet

    Argon2id
    A memory-hard password hash, winner of the Password Hashing Competition 2015. OWASP’s first choice.
    Avalanche effect
    One changed input bit flips about half of the output bits.
    bcrypt
    A slow password hash from 1999 with a cost factor and a built-in salt.
    Brute force
    Trying every possible password until one matches.
    Collision
    Two different inputs with the same hash.
    Cost factor
    How much work a password hash does. In bcrypt each +1 doubles it.
    Digest
    Another word for the output of a hash function.
    HMAC
    A hash with a secret key. Proves who made a message and that it wasn’t changed.
    k-anonymity
    Sending only a short prefix of a hash, so the service can’t tell what you looked up.
    Length extension
    An attack on sha256(key + message) that HMAC prevents.
    Lookup table
    Hashes of known words, computed in advance and searched by hash.
    Memory-hard
    Needs a lot of memory per guess, which slows down graphics cards.
    Pepper
    A secret value added to all passwords and kept outside the database. Optional, on top of salt.
    Salt
    A random value per password, stored next to the hash. Makes equal passwords hash differently.

    Searches the list of pages on this site. What you type stays in your browser.