What Is a Hash Function? MD5, SHA-256 and Bcrypt Explained
Security · Published October 8, 2026 · Updated October 24, 2026 · 3 min read
Written by Akinrinmade Michael · General information, not professional advice
A hash function turns any amount of data into a short, fixed-length fingerprint. Hash the word hello and you always get the same result. Change one letter and the fingerprint changes completely. That simple behavior sits behind file checks, digital signatures, version control and the way websites store passwords.
SHA-256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
MD5("hello") = 5d41402abc4b2a76b9719d911017c592Four properties that matter
- Same input, same output. That makes hashes useful for checking that a file hasn't changed.
- One way. You can't work backwards from a hash to the original data.
- Fixed size. SHA-256 always gives 256 bits (64 hex characters), whether you hash one word or a whole movie.
- Tiny changes spread. Changing one character changes the whole hash.
You can see the last one for yourself. Hashing hello and Hello with SHA-256 gives two results that share no obvious pattern, even though the inputs differ by a single capital letter.
A walk through the idea
Imagine a machine that chews through data in blocks, mixing each block with the running result using a fixed set of shuffling steps, and then outputs what's left. The same data always shuffles the same way, so the output is repeatable. But so much information is thrown away on the way that you can't rebuild the input from the output, any more than you can rebuild a cow from a hamburger.
Because the output is a fixed size and the input isn't, two different inputs must sometimes share a hash. That's called a collision. A good algorithm makes collisions so rare that nobody can find one on purpose.
Which algorithms are still safe?
| Algorithm | Output size | Status | Fine for |
|---|---|---|---|
| MD5 | 128 bits | Broken for security | Spotting accidental corruption, quick cache keys |
| SHA-1 | 160 bits | Broken for security | Legacy systems only |
| SHA-256 | 256 bits | Secure | Checksums, signatures, integrity checks |
| SHA-512 | 512 bits | Secure | Same as SHA-256, with a longer result |
| bcrypt | 60-character string | Secure and slow by design | Storing passwords |
"Broken" for MD5 and SHA-1 means attackers can build two different inputs that share a hash. That ruins them for signatures and certificates, where one input has to prove the identity of another. For catching a corrupted download, where nobody is attacking you, they still do the job.
What people use hashes for
- Checking downloads. A site publishes the SHA-256 of a file. You hash your copy, and if the two match, the file arrived intact. The guide on verifying downloads with checksums walks through it.
- Finding duplicates. Two files with the same hash are, for all practical purposes, the same file.
- Version control. Git names every commit and file by its hash, so any change shows up as a new name.
- Signatures. Software signs the hash of a document instead of the whole thing, which is faster.
- Storing passwords. A site keeps a hash of your password, never the password itself.
Hashing isn't the same as encryption
Encryption can be reversed with a key. Hashing can't be reversed at all. That's why hashes are used to store passwords: the site can check a password without ever keeping the real one. If you need to get the original data back later, you want encryption, not a hash.
Why passwords need bcrypt
SHA-256 is designed to be fast, which is exactly wrong for passwords. A fast hash lets an attacker try billions of guesses per second on a stolen list. Password hashes such as bcrypt are deliberately slow and add a random salt, a bit of extra data mixed in, so two users with the same password get different hashes and precomputed tables of common passwords are useless.
bcrypt also has a cost setting. Each step up doubles the work, so you can raise it as computers get faster. Use the Bcrypt Generator to see how a bcrypt hash looks and to check a password against one.
Common mistakes
- Using MD5 or plain SHA-256 to store passwords.
- Hashing without a salt, which lets attackers reuse one table against every account.
- Thinking a hash hides short or common input. Hashes of easy passwords like
123456are well known and instantly reversed by lookup. - Comparing hashes with different line endings or hidden spaces in the input. A trailing newline changes the whole result.
Try it
Paste text or choose a file in the Hash Generator to see all the common hashes at once. And if you're creating a password, make it long and random with the Password Generator.