What is hashing?
A hash is a one-way fingerprint of data. Same input, same fingerprint — change the data, even slightly, and the fingerprint changes beyond recognition.
In this lesson
- Define a hash function in one sentence
- Explain why hashing is one-way
- Run a hash from the terminal and read the output
A fingerprint for data
A hash function takes an input of any size — a word, a photo, an entire blockchain — and returns a fixed-size string of bytes called a digest or hash. The same input always produces the same digest, every time, on every machine.
Think of it as a fingerprint: you can always compute it from the data, but you cannot rebuild the data from the fingerprint.
Three properties make hashes useful everywhere in security:
| Property | What it means in practice |
|---|---|
| Deterministic | The same input always yields the same digest — you can re-check anything later. |
| One-way | Given a digest, recovering the input is computationally infeasible. |
| Avalanche effect | A one-bit change in the input changes roughly half of the output bits. |
Example · Checking a download
You download a 4 GB installer and the website publishes SHA-256: 9f2b…c41a. You hash the file locally, get the same digest, and know the download is byte-for-byte identical — no need to trust the connection.
The same trick protects git commits, package managers and firmware updates.
echo -n "Hello Blockchain" | sha256sum\n# 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069 -
Hashing is not encryption
Encryption is reversible: you decrypt with a key. Hashing is one-way — there is no key and no way back. You cannot "decrypt" a hash; you can only compare it.
Hash playground
Type two sentences, hash them and compare. Then change a single character and watch the digest explode.
Is a hash the same as a checksum?
A checksum is a hash used to detect accidental corruption. Cryptographic hashes additionally resist attackers who deliberately try to produce two inputs with the same digest.
Do hashes use a secret key?
Plain hashes (SHA-256) do not. If you need a key — say, to authenticate a message — you use HMAC, which is built on top of a hash function.
What if the input is huge?
Hash functions stream data in fixed-size blocks, so you can hash a 100 GB file with a few kilobytes of memory.
Check your understanding
Practice · server-gradedProperties of a hash
Practice · server-gradedPractice exercise
Practice: hash basics
Practice
- Hash basics — practice Start