Hashing Explained: MD5, SHA-256 and bcrypt Hash Functions
Hashing is one of the most useful ideas in computing, and one of the most misunderstood. People say "encrypt the password" when they mean "hash the password," and the difference matters a great deal for security. This guide explains what a hash function is, how MD5, SHA-256 and bcrypt differ, and when to use each — with tools you can try in your browser.
What is a hash function?
A hash function takes any input — a word, a file, a whole book — and produces a fixed-length string of characters called a hash or digest. Feed it "hello" and you always get the same output; feed it the complete works of Shakespeare and you get an output of exactly the same length. A good cryptographic hash has four key properties:
- Deterministic — the same input always gives the same hash.
- Fixed length — the output size never changes, whatever the input.
- One-way — you cannot reverse the hash back into the original input.
- Avalanche effect — changing a single character of the input changes the whole hash completely.
You can see all of this immediately with the PAYATE Hash Generator: type some text, change one letter, and watch the entire hash transform.
Hashing is not encryption
This is the single most important distinction. Encryption is two-way: you encrypt data with a key and later decrypt it back to the original. Hashing is one-way: there is no "unhash" function. That is exactly why hashing is right for passwords — the system never needs to know your actual password, only whether the hash of what you typed matches the stored hash. If you genuinely need reversible protection for text, that is encryption's job; you can try it with the AES Text Encryption tool instead.
What hashing is used for
- Storing passwords — services store the hash of your password, never the password itself, so a database leak does not immediately expose it.
- File integrity — a download page may publish a file's SHA-256 hash so you can confirm your copy was not corrupted or tampered with.
- Digital signatures and certificates — hashing underpins how documents and TLS certificates are signed.
- Deduplication and lookups — hashes make fast fingerprints for comparing large pieces of data.
MD5: fast but broken
MD5 produces a 128-bit (32-hex-character) hash and was once everywhere. Today it is considered cryptographically broken: researchers can deliberately create two different inputs with the same MD5 hash, called a collision. That means you must never use MD5 for passwords or security. It still has harmless uses — a quick, non-security checksum to spot accidental file corruption — but treat it as a legacy tool, not a safe one.
SHA-256: the modern standard for integrity
SHA-256 is part of the SHA-2 family and produces a 256-bit (64-hex-character) hash. It has no known practical collisions and is the workhorse for file integrity, digital signatures and blockchains. When a Linux distribution or a software vendor lists a "SHA-256 checksum" next to a download, you hash your downloaded file and compare — if the two strings match, the file is intact. You can compute MD5, SHA-1, SHA-256 and SHA-512 side by side with the Hash Generator.
But here is the catch: SHA-256 is fast, and for passwords, fast is bad.
Why fast hashes are wrong for passwords
If a website stored your password as a plain SHA-256 hash and the database leaked, an attacker could try billions of guesses per second on ordinary hardware, hashing each candidate and comparing. Common passwords would fall in moments. The speed that makes SHA-256 great for checksums makes it dangerous for passwords.
The fix is a password hashing function that is deliberately slow and salted.
bcrypt: built for passwords
bcrypt is designed specifically for hashing passwords. It does two things a plain hash does not:
- It is deliberately slow, with an adjustable "cost factor." You can tune it so one hash takes a fraction of a second — unnoticeable at login, but devastating for an attacker trying billions of guesses.
- It salts automatically. A random salt is generated per password and stored inside the hash, so two users with the same password get different hashes, and precomputed "rainbow table" attacks fail.
A bcrypt hash encodes the algorithm, the cost and the salt all in one string, which is why it starts with something like $2b$12$. You can create and check one with the Bcrypt Generator & Verifier. Modern alternatives such as scrypt and Argon2 follow the same philosophy of being intentionally expensive.
Salting: why it matters
A salt is random data added to a password before hashing. Without salting, identical passwords produce identical hashes, so an attacker can crack many accounts at once and reuse precomputed tables. With a unique salt per user, every hash is different and each must be attacked individually. bcrypt handles salting for you; if you ever roll your own, never skip it and never reuse a salt.
Choosing the right tool
- Checking a file downloaded correctly? Use SHA-256.
- Storing user passwords? Use bcrypt (or Argon2/scrypt) — never a plain SHA or MD5.
- Need a quick, non-security fingerprint? MD5 or CRC32 is fine for spotting accidental corruption only.
- Need to get the data back later? That is encryption, not hashing — reach for AES.
Key takeaways
A hash function turns any input into a fixed-length, one-way digest. MD5 is fast but broken and should never secure anything; SHA-256 is the modern standard for file integrity and signatures; bcrypt is purpose-built for passwords because it is slow and salted. The golden rule: hashing is not encryption, and fast general-purpose hashes are the wrong choice for passwords. Experiment with the Hash Generator and the Bcrypt Generator to see the difference for yourself.