← Learn

What Is a Hash Function?

Updated 29 April 2026

A plain-English guide to hash functions — how MD5, SHA-1, SHA-256, and SHA-512 work, why they are one-way, what makes them useful for checksums and passwords, and when not to use them.

What a hash function does

A hash function takes any input — a word, a file, an entire database — and produces a fixed-length string called a hash (or digest). Feed in the same input and you always get the same hash. Change even one character and the hash changes completely.

SHA-256("hello")
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
SHA-256("hello!") — one character added
ce06092fb948d9ffac7d1a376e404b26b7575bcc11ee05a4615fef4fec3a308b

This property — tiny input changes causing wildly different outputs — is called the avalanche effect. It is fundamental to why hash functions are useful.

Hash functions are one-way

You cannot reverse a hash back to the original input. This is by design. A good hash function is a mathematical one-way street — given the output, there is no efficient algorithm to find the input that produced it.

This makes them useful for verifying data without storing the data itself. For example, a website can store the hash of your password instead of the password — when you log in, it hashes what you type and compares it to the stored hash.

Common hash algorithms compared

AlgorithmOutput sizeStatusUse today?
MD5128-bit / 32 charsBrokenChecksums only — never security
SHA-1160-bit / 40 charsBrokenLegacy only — avoid
SHA-256256-bit / 64 charsSecureYes — general purpose
SHA-512512-bit / 128 charsSecureYes — where extra strength needed

What are hash functions used for?

  • File integrity — software distributors publish SHA-256 hashes of download files. You hash the file you downloaded and compare — if they match, the file is untampered.
  • Password storage — websites store hashes of passwords, not the passwords themselves. A breach exposes hashes, not plain text. (Note: use bcrypt/Argon2 for passwords, not raw SHA-256 — see how passwords are hashed.)
  • Digital signatures — signing a document hashes it first, then encrypts the hash. Verifying the signature re-hashes the document and compares.
  • Data deduplication — hash a file to get a unique fingerprint. Two files with the same hash are identical, so you can safely store only one copy.
  • Blockchain — each block contains the hash of the previous block, creating a tamper-evident chain. Changing any block invalidates every block after it.

Collisions — why MD5 is broken

A collision is when two different inputs produce the same hash. For a secure hash function, finding a collision should be computationally infeasible. MD5 and SHA-1 have been broken in this sense — researchers can craft two different files that produce the same hash. This makes them unsuitable for security purposes.

SHA-256 has no known practical collisions. Its 256-bit output space is so large that even with all the world's computing power it would take longer than the age of the universe to find one by brute force.

Related guides

Generate MD5, SHA-1, SHA-256 and SHA-512 hashes

Paste any text and get its hash instantly — all processing happens in your browser

What Is a Hash Function? | DataToolkit | DataToolkit