What Is a Hash Function?
A cryptographic hash function is a mathematical algorithm that takes input data of arbitrary size and produces a fixed-size output called a hash, digest, or checksum. Hash functions are designed to be deterministic (the same input always produces the same output), fast to compute, and practically impossible to reverse. Even a single-character change in the input produces a completely different hash — a property known as the avalanche effect.
Hash functions are fundamental to modern computing and security. They are used in password storage, digital signatures, data integrity verification, blockchain technology, file deduplication, and many other applications.
Supported Hash Algorithms
MD5 (128-bit)
Developed by Ronald Rivest in 1991, MD5 produces a 128-bit (32 hex character) hash. While once widely used, MD5 is now considered cryptographically broken due to demonstrated collision attacks. It should not be used for security-sensitive applications. However, it remains useful for checksums, cache keys, and non-cryptographic fingerprinting.
SHA-1 (160-bit)
Published by NIST in 1995, SHA-1 produces a 160-bit (40 hex character) hash. In 2017, Google demonstrated a practical collision attack (SHAttered), and SHA-1 is now considered insecure for cryptographic use. Major browsers and certificate authorities have deprecated SHA-1 for SSL/TLS certificates.
SHA-256 (256-bit)
Part of the SHA-2 family designed by the NSA and published by NIST in 2001. SHA-256 produces a 256-bit (64 hex character) hash. It is widely used in security applications, blockchain (Bitcoin uses SHA-256), digital certificates, and password hashing. No practical attacks have been found against SHA-256.
SHA-384 (384-bit)
Also part of the SHA-2 family, SHA-384 is a truncated version of SHA-512. It produces a 384-bit (96 hex character) hash and provides a higher security margin than SHA-256. It is commonly used in government and financial applications requiring stronger security guarantees.
SHA-512 (512-bit)
The largest member of the SHA-2 family commonly used. SHA-512 produces a 512-bit (128 hex character) hash. On 64-bit processors, SHA-512 can actually be faster than SHA-256 because it processes data in 64-bit words. It is preferred when maximum hash security is needed.
Hash Function Properties
- Deterministic: The same input always produces the same hash output.
- Fixed output size: Regardless of input size, the hash is always the same length (e.g., 256 bits for SHA-256).
- Avalanche effect: A small change in input produces a dramatically different hash.
- Pre-image resistance: Given a hash, it is computationally infeasible to find the original input.
- Collision resistance: It is computationally infeasible to find two different inputs that produce the same hash.
- Fast computation: Hashes can be computed quickly for any input size.
Common Uses of Hash Functions
- Password storage: Passwords are hashed before storage so that even if the database is compromised, the original passwords are not exposed. (Note: purpose-built password hashing functions like bcrypt or Argon2 are preferred over raw SHA-256.)
- File integrity: Download sites provide hash checksums so you can verify that a downloaded file has not been corrupted or tampered with.
- Digital signatures: Hash functions are used to create a digest of a message that is then encrypted with a private key.
- Blockchain: Cryptocurrencies like Bitcoin use SHA-256 to link blocks together and verify transactions.
- Data deduplication: Storage systems use hashes to identify duplicate data blocks and avoid storing them multiple times.
Frequently Asked Questions
What is a hash function?
A hash function converts input data of any size into a fixed-size output. The same input always produces the same output, but even a tiny change produces a completely different hash. Hash functions are one-way — you cannot reverse a hash to find the original input.
Which hash algorithm should I use?
For security purposes, use SHA-256 or SHA-512. MD5 and SHA-1 are cryptographically broken and should only be used for non-security purposes like checksums or cache keys. SHA-256 is the most widely used secure hash algorithm today.
Is MD5 still safe to use?
MD5 is not safe for cryptographic purposes because collision attacks have been demonstrated. It remains acceptable for non-security uses like file checksums and data deduplication where collision resistance is not critical.
Related Tools
- Base64 Encoder/Decoder — Encode or decode Base64 strings.
- Password Generator — Generate strong, secure passwords.