appzasGamesToolsDevLearnReferenceNetworkTimeCalculatorsCompareLLM prices

What is a hash?

Lesson 1 of 48 minBeginner

A hash is a fixed-size fingerprint of data. Learn its properties and where it is used.

A hash function turns any input, from one letter to a movie file, into a short fixed-length value called a hash or digest. Think of it as a fingerprint of the data.

SHA-256 of the three letters "abc" (always the same result)
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad

Properties of a good cryptographic hash

  • Deterministic: the same input always gives the same hash.
  • Fixed size: SHA-256 always produces 256 bits (64 hex characters), whatever the input.
  • One-way: you cannot work backwards from the hash to the input.
  • Avalanche effect: changing one bit of the input changes the hash completely.
  • Collision resistant: it is infeasible to find two different inputs with the same hash.

Common algorithms

AlgorithmOutputStatus
MD5128 bitsBroken for security. Collisions are easy. Fine only for non-security checksums.
SHA-1160 bitsBroken for collision resistance. Avoid for new uses.
SHA-256, SHA-512256 / 512 bitsSecure and widely used (SHA-2 family).
SHA-3variableA newer standard built differently from SHA-2.

What hashes are used for

  • Integrity: check a file was not changed or corrupted.
  • Digital signatures: sign the hash of a message instead of the whole message.
  • Deduplication: identify identical files cheaply.
  • Password storage: with special, slow hash functions (lesson 3).

NoteTry it: open the hash generator and type "abc", then "abd". One letter changes the whole output. That is the avalanche effect.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. How long is a SHA-256 hash, whatever the input size?
2. Which statement describes the avalanche effect?
3. Which algorithm should you avoid for security purposes?

Key terms