What is Hash Function?

A hash function maps data of any size to a fixed-length string, producing the same output for the same input and used for integrity and lookups.

A hash function is an algorithm that takes an input of any size and produces a fixed-length output called a hash, digest, or checksum. The same input always yields the same output, but even a one-character change to the input produces a completely different hash. This deterministic, fixed-length behavior makes hash functions foundational to computing, from data structures to security.

Good cryptographic hash functions have several defining properties. They are deterministic and fast to compute, but practically impossible to reverse — you cannot derive the input from the hash. They are collision-resistant, meaning it is infeasible to find two inputs that produce the same output, and they exhibit the avalanche effect, where small input changes drastically change the output.

Hash functions serve distinct purposes depending on the family. Cryptographic hashes like SHA-256 verify data integrity, power digital signatures, and underpin blockchains. Non-cryptographic hashes prioritize speed for hash tables and checksums. Password storage uses deliberately slow, salted hashing algorithms designed to resist brute-force attacks — a different requirement from fast general-purpose hashing.

A common confusion is between hashing and encryption. Encryption is reversible with a key so data can be recovered; hashing is one-way by design and cannot be undone. This is why passwords should be hashed, not encrypted: even if the database leaks, the original passwords are not directly recoverable. Verifying a file's integrity by comparing its hash against a published value is another everyday use.

Examples

  • SHA-256 of 'hello' is a fixed 64-character hex string, unique to that input
  • Changing 'hello' to 'Hello' produces a completely different hash
  • Verifying a download by comparing its SHA-256 checksum to the published one

Frequently asked questions

Free tools for working with Hash Function

Related terms