LineLapse BlogMake your own →
← All posts

Hash Functions Explained

#hashing#security#computer-science

Feed a hash function a birthday card or the entire text of a library, and it hands back a short, fixed-length string of characters — a kind of digital fingerprint. Change a single comma in the input and the fingerprint changes completely. That simple, one-way trick quietly powers passwords, downloads, and much of the software you use every day. Here's what a hash function actually is, and why it matters.

Hash Functionsthe invisible lock on your dataAny InputHash Functiona7f3e9...FilePasswordAnything← That's the hashInput + 1 bitHash Function9k2m5x...3 Big JobsIntegrity1ComparePasswords2LoginSpeed3Hash TableCollisionsame hash!GoodBadSHA-256MD5bcryptYour Lock
▶ Watch it draw

What a hash function does

A hash function is a recipe that turns any input — text, a file, a whole video — into a fixed-size output called a hash or digest. No matter how big or small the input, the output is always the same length, often something like 64 characters. The same input always produces the same hash, so it's completely predictable. But the reverse is not: given a hash, you can't work backwards to recover the original input. That's why hashing is called a one-way function.

Think of it like blending a smoothie. You can throw fruit into a blender and get a specific smoothie every time, but no one can unblend it back into whole strawberries and a banana. A good hash function makes that unblending practically impossible.

The two properties that make it useful

Two features do most of the heavy lifting.

First, tiny changes cause huge changes. Flip one bit of the input and roughly half the output bits flip too. This is called the avalanche effect, and it means two nearly-identical inputs produce wildly different hashes with no visible resemblance. You can't nudge the input to steer the output.

Second, collisions are extremely rare. A collision is when two different inputs happen to produce the same hash. Because the output space is astronomically large, a well-designed hash function makes finding a collision so unlikely that it's treated as impossible for practical purposes. If two files have the same hash, you can trust they're the same file.

Why it matters: checking without comparing

These properties unlock a surprisingly wide range of everyday uses.

Verifying downloads. When you download a large program, the site often lists its expected hash. Your computer hashes the file you received and compares the two short strings. If they match, the file arrived intact and untampered; if a single byte was corrupted or altered, the hashes won't match. You've confirmed a gigabyte-sized file by comparing two tiny fingerprints.

Storing passwords safely. Good services never store your actual password. Instead they store its hash. When you log in, they hash what you typed and check it against the stored hash. If their database is stolen, attackers get a pile of fingerprints, not passwords — and because hashing is one-way, they can't simply reverse them. (Real systems add extra ingredients like a random salt to make attacks even harder, but the hash is the foundation.)

Finding things fast. Programs use hashing to organize data in structures called hash tables, which let them look up a value almost instantly instead of searching through everything. Much of the speed you take for granted in software comes from this trick.

Hashing is not encryption

It's a common mix-up worth clearing up. Encryption is reversible — it scrambles data so that someone with the right key can unscramble it later. Hashing is deliberately not reversible; there's no key and no way back. You hash something precisely when you never need the original returned, only a way to check whether two things match. Encryption keeps a secret you'll want to read again; hashing produces a fingerprint you only ever compare.

The takeaway

A hash function is a one-way recipe that turns any input into a short, unique fingerprint. Because the same input always gives the same output, tiny changes scramble it completely, and collisions are vanishingly rare, hashes let computers answer one question quickly and reliably: is this exactly the thing I expected? That quiet question sits underneath secure logins, trustworthy downloads, and fast software — which is why hash functions matter far more than their humble size suggests.


This explainer was made with LineLapse — type a topic, get a hand-drawn video. Make your own →