Two different things that get mixed up
The sentence "we encrypt our passwords" is usually wrong; in a correct implementation, passwords are hashed. The two concepts are confused constantly, even though they point in different directions. Encryption is two-way: whoever holds the key can reverse it. Hashing is one-way: there is no way back, only comparison. Knowing which fits which job is the difference between a data breach being bad news and being a disaster.
What hashing is
A hash function turns input of any length into a fixed-length fingerprint. SHA-256("hello") always produces the same 64-character output; change one letter of the input and the output changes completely. In a good hash function there is no practical way to recover the input from the output, and finding two different inputs with the same output must be computationally infeasible.
Three typical uses:
- Integrity checks: if the hash of a downloaded file matches the one the publisher lists, the file is intact and unmodified.
- Password storage: the hash is stored instead of the password; at login the entered password is hashed and compared.
- Signatures and identifiers: digital signatures, Git commit ids and content-addressed storage are all built on hashes.
What encryption is
Encryption makes data unreadable with a key and allows it to be recovered with the same key (symmetric, such as AES) or a paired key (asymmetric, such as RSA). You use encryption when you need to read the data again later: disk encryption, HTTPS traffic, card data in a database, backups. Its security rests entirely on the secrecy of the key; if the key sits in the source code, the encryption is decorative. To experiment with text, the encryption tool is a quick way to see it in action.
MD5, SHA-256, bcrypt: which one for what?
MD5
Fast and available everywhere, but broken against collision attacks for years: two different files with the same MD5 can be manufactured. It must not be used for security. It still appears in non-security roles such as cache keys or detecting accidental corruption in transit, but a new project does not need it even for those.
SHA-256
Part of the SHA-2 family and today's standard choice for file integrity, digital signatures and HMAC. Secure and fast. Fast is exactly the problem: it is too fast for passwords. Modern hardware computes billions of SHA-256 hashes per second, so short and common passwords in a leaked table are recovered within hours. Adding a salt prevents two users with the same password from sharing a hash and defeats precomputed tables, but it does not slow anything down.
bcrypt (and Argon2, scrypt)
These are password hashing functions, deliberately designed to be slow. bcrypt takes a cost factor; each increment doubles the time. It generates its own salt and embeds it in the output, so no separate column is needed. Tens of milliseconds at login are invisible to the user and cut an attacker's guessing rate by orders of magnitude. For new projects Argon2id is the preferred choice; bcrypt, with its broad support and long track record, remains a safe one.
Decision table
- Will you need to read the data again? → Encryption (an authenticated mode such as AES-256-GCM; keep the key separate from the code).
- Do you need to tell whether a file or message changed? → SHA-256 (HMAC-SHA256 if the check must be keyed).
- Are you storing passwords? → bcrypt / Argon2id. Never plain SHA-256, never MD5, never your own algorithm.
- Do you have legacy MD5 passwords? → Verify the old hash on the user's next login and store a new bcrypt hash; for a bulk migration you do not need the plaintext, you can feed the existing hash into bcrypt as its input.
Common mistakes
- Encrypting passwords and keeping the key on the same server. When the server is compromised, the passwords go with it.
- Believing "double hashing" (
md5(sha1(x))) adds security. It does not solve the speed problem. - Using a fixed salt, or no salt at all.
- Comparing hashes with a comparison that is not constant-time.
- Using a hash where encryption is needed: "anonymizing" email addresses with SHA-256 and believing they are anonymous. When the input space is small, the hash is reversed by guessing.
Conclusion
The rule fits in three sentences: if you will read it back, encrypt it; if you need to know whether it changed, hash it; if it is a password, hash it slowly. To see how a string looks under different algorithms or to produce a checksum for a file, the hash tool shows MD5, SHA-1 and SHA-256 side by side. For passwords, remember to use bcrypt on the server, never in the browser.