$devtoolkit.sh/glossary/what-is-hash

What is a Hash Function? — Cryptographic Hashing Explained

Definition

A hash function is a mathematical function that takes an input of any size and produces a fixed-size output called a hash, digest, or checksum. A cryptographic hash function has four key properties: it is deterministic (same input always produces the same output), fast to compute, one-way (infeasible to reconstruct the input from the output), and collision-resistant (infeasible to find two different inputs that produce the same output). These properties make hashing useful for verifying data integrity, storing passwords, and building digital signature schemes.

How It Works

Modern hash functions like SHA-256 process input in blocks, applying a series of bitwise operations, modular additions, and compression functions that mix the bits thoroughly. Each tiny change in the input produces a completely different output (the avalanche effect). SHA-256 always produces a 256-bit (32-byte) output, represented as a 64-character hex string. MD5 produces 128-bit output — it is fast but cryptographically broken (collision attacks exist) and should only be used for non-security checksums. bcrypt and Argon2 are specialized slow hash functions designed for password storage.

Common Use Cases

  • Storing passwords as hashes — if the database is breached, plaintexts are not exposed
  • Verifying file integrity with checksums (download pages often publish SHA-256 hashes)
  • Building digital signatures and certificate fingerprints
  • Deduplicating content by comparing hashes instead of full file bytes
  • Hash tables and bloom filters use hashing for O(1) average lookup

Example

SHA-256("Hello") → 185f8db32921bd46d35a7de6b5ce4f6a1b634e2cb3e7e4e82d3a8e1b8c7a1234

SHA-256("Hello!") → completely different hash
185f8db3... → input slightly changed but entire output changes

bcrypt("password") → $2b$12$randomsalt...hashed (includes salt and cost)

Related Tools

FAQ

Why is MD5 no longer safe for security?
MD5 is broken for cryptographic purposes because researchers have demonstrated practical collision attacks — it is possible to construct two different inputs with the same MD5 hash. Do not use MD5 for password storage or digital signatures. It is still acceptable for non-security checksums where speed matters.
What is the difference between hashing and encryption?
Hashing is one-way: you cannot recover the original input from the hash. Encryption is two-way: with the correct key you can decrypt the ciphertext back to plaintext. Passwords should be hashed, not encrypted — if the key is compromised, all encrypted passwords are exposed.
What is a salt in password hashing?
A salt is a unique random value concatenated to the password before hashing. Salts prevent rainbow table attacks (precomputed hash tables) because each password has a different salt and therefore a different hash even if two users have the same password. bcrypt and Argon2 handle salting automatically.

Related Terms

/glossary/what-is-hashv1.0.0