Hashing is one of those concepts that sits at the heart of modern computing — passwords, file downloads, Git commits, blockchain — all of them rely on it. But the term gets used in confusing ways, and the difference between a bad choice (MD5 for passwords) and a good one (bcrypt) has real security consequences.
Here's a clear explanation of what hashing is, how to choose the right algorithm, and how to hash a string in your browser or in code.
What is hashing?
A hash function takes any input — a word, a sentence, an entire file — and produces a fixed-length output called a hash or digest.
"hello" → SHA-256 → 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Three properties make hash functions useful:
- Deterministic. The same input always produces the same output. Hash "hello" a million times, you get the same result.
- One-way. You cannot reverse a hash back to the original input. There's no "unhash" function. You can only verify by hashing again and comparing.
- Avalanche effect. A tiny change in input produces a completely different output. "hello" and "Hello" share zero bytes in their SHA-256 hashes.
This is different from encryption, which is reversible if you have the key. Hashing is intentionally irreversible.
Common hash algorithms
MD5
MD5 produces a 128-bit (32-character hex) hash. It's fast and still widely used for checksums and file verification — for example, to confirm that a downloaded file wasn't corrupted in transit.
Do not use MD5 for passwords or security-critical purposes. MD5 is cryptographically broken. Attackers can generate collisions (two different inputs with the same hash), and precomputed rainbow tables make it trivially easy to reverse common MD5 password hashes.
SHA-1
SHA-1 produces a 160-bit (40-character) hash. Like MD5, it's now considered weak for cryptographic purposes. Google demonstrated a SHA-1 collision in 2017. It's still used in some legacy systems but should be avoided in new code.
SHA-256
SHA-256 is part of the SHA-2 family and produces a 256-bit (64-character) hash. It's currently the general-purpose standard for most security applications: file integrity, digital signatures, TLS certificates, and more. Bitcoin uses SHA-256 for its proof-of-work.
If you're hashing anything that isn't a password, SHA-256 is usually the right choice.
SHA-512
SHA-512 produces a 512-bit (128-character) hash. It offers more theoretical security than SHA-256 and is marginally faster on 64-bit CPUs for large inputs. In practice, SHA-256 is sufficient for almost every real-world use case.
SHA-3 (Keccak)
SHA-3 is a completely different design from SHA-2, chosen by NIST as a backup in case SHA-2 is ever broken. It's not widely used in practice today because SHA-2 remains secure, but it's available in most modern libraries.
bcrypt / scrypt / Argon2
These are password hashing algorithms, and they're fundamentally different from the ones above. They're intentionally slow and memory-hard, which makes brute-force attacks expensive. SHA-256 can compute billions of hashes per second on modern hardware — that's terrible for passwords. bcrypt might compute a few thousand per second. That's the point.
Rule: If you're hashing passwords, use bcrypt, scrypt, or Argon2. Never use MD5, SHA-1, or SHA-256 directly.
Hashing in code
JavaScript / Node.js (SHA-256):
const crypto = require('crypto');
const hash = crypto.createHash('sha256').update('hello').digest('hex');
console.log(hash);
// 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Python:
import hashlib
hash = hashlib.sha256(b"hello").hexdigest()
print(hash)
# 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Go:
import (
"crypto/sha256"
"fmt"
)
h := sha256.Sum256([]byte("hello"))
fmt.Printf("%x\n", h)
PHP:
echo hash('sha256', 'hello');
Command line (macOS/Linux):
echo -n "hello" | sha256sum
Note the -n flag — without it, echo adds a newline character and the hash will be different.
What are hashes used for?
File integrity. When you download software, the vendor often provides an MD5 or SHA-256 checksum. You hash the downloaded file and compare it to the published hash. If they match, the file wasn't tampered with.
Password storage. Web apps never store passwords in plain text. Instead they store a hash of the password. When you log in, the server hashes your input and compares hashes.
Git commits. Every Git commit is identified by a SHA-1 hash of its contents. Changing anything about a commit produces a completely different hash.
Data deduplication. Hash a file, use the hash as the key. If two files have the same hash, they're identical — no need to store duplicates.
Digital signatures. Sign the hash of a document, not the document itself. Faster and equally secure.
Hash a string online
If you need to quickly hash a string without writing code, use Toolmingo's Hash Generator. It supports MD5, SHA-1, SHA-256, and SHA-512 and runs entirely in your browser. Nothing is sent to a server.
Useful for verifying checksums, testing API authentication schemes, or understanding how hashes work by experimenting with different inputs.
FAQ
Q: Can I reverse a SHA-256 hash back to the original string? No. That's the fundamental property of hash functions — they're one-way. You can only verify a hash by hashing the candidate input again and comparing. However, if the input is short or common (like a weak password), an attacker can hash millions of candidates until one matches. That's why you use slow algorithms for passwords.
Q: Is "encryption" the same as "hashing"? No. Encryption is reversible with a key. Hashing is irreversible. People sometimes say "encrypt a password" when they mean "hash a password" — this is incorrect and matters in security discussions.
Q: My hash looks different depending on the tool. Why? Most likely a whitespace issue. A trailing newline, a leading space, or a hidden character will change the hash. Make sure you're hashing exactly the same bytes. Also check the encoding — some tools output Base64, others output hexadecimal.
Q: Is MD5 okay for non-security uses? Yes. If you just need to detect file corruption (not tampering), MD5 is fine and its speed is an advantage. Use SHA-256 if the data's authenticity also matters.