A hash function takes any input — a word, a file, an entire database — and produces a fixed-length string of characters called a digest. Change a single character in the input and the entire digest changes completely. Feed in the same input twice and you always get the same output. That combination of properties makes hashing one of the most useful tools in computing.

What does a hash actually look like?

Take the word hello and run it through each algorithm:

AlgorithmOutput (hex)Length
MD55d41402a bc4b2a76 b9719d91 1017c59232 chars
SHA-1aaf4c61d dcc5e8a2 dabede0f 3b482cd9 aea9434d40 chars
SHA-2562cf24dba 5fb0a30e 26e83b2a c5b9e29e 1b161e5c 1fa7425e 73043362 938b982464 chars
SHA-5129b71d224… (much longer)128 chars

Notice that even though hello is only 5 characters, the output length is always fixed regardless of input size — that is a defining property of hash functions.

The key properties of a good hash function

MD5 — fast but broken

MD5 produces a 128-bit (32-character hex) digest. It was designed in 1991 and was once the standard for checksums and password hashing. Today it is considered cryptographically broken — researchers can generate deliberate collisions in seconds on consumer hardware.

Do not use MD5 for security. It is still useful for non-security tasks: quickly verifying a file download was not corrupted, generating cache keys, or creating unique IDs in low-stakes situations.

SHA-1 — deprecated, avoid where possible

SHA-1 produces a 160-bit (40-character hex) digest. It was the successor to MD5 and used widely in SSL certificates and Git commits. In 2017 Google's research team produced the first real-world SHA-1 collision (the SHAttered attack). Major browsers and certificate authorities have since dropped support.

SHA-1 is deprecated for security use. Git still uses it internally for object naming (not as a security measure), but new systems should use SHA-256 or above.

SHA-256 — the current standard

SHA-256 is part of the SHA-2 family and produces a 256-bit (64-character hex) digest. No practical collision attack exists against it. It is used in TLS certificates, code signing, Bitcoin's proof-of-work, and most modern security systems.

When in doubt, use SHA-256. It balances security strength and performance well for the vast majority of use cases.

SHA-512 — extra strength

SHA-512 produces a 512-bit (128-character hex) digest. It is not significantly more secure than SHA-256 against current threats, but it can actually be faster on 64-bit CPUs because the algorithm works with 64-bit word operations internally. It is preferred in some high-security contexts.

Quick reference: which to use

AlgorithmBit lengthSecurityGood for
MD5128 Broken Checksums, cache keys, non-security deduplication
SHA-1160 Deprecated Legacy systems, Git internals (non-security)
SHA-256256 Secure Certificates, code signing, password hashing, APIs
SHA-512512 Secure High-security contexts, 64-bit performance-sensitive systems

Hashing is not encryption

A common misconception: hashing and encryption are not the same thing. Encryption is reversible — given the key, you can decrypt the data back. Hashing is one-way — there is no key, no reverse operation. This is why passwords should be hashed (stored as a hash) rather than encrypted: even if the database is breached, the original passwords cannot be recovered from the hashes.

For password storage specifically, use a dedicated password-hashing function like bcrypt, scrypt, or Argon2 rather than raw SHA-256. These are designed to be slow and resist brute-force attacks.

File integrity verification

One of the most practical everyday uses of hashing is verifying that a downloaded file arrived intact. When you download software, the publisher often lists the SHA-256 hash of the file. After downloading, you run the same hash function on the file and compare the result. If they match, the file was not tampered with or corrupted in transit.