Tech 8 min read·By NexTool Team

Understanding Hash Functions: SHA-256, MD5 & More

Learn how hash functions work and their uses in security, data integrity, and programming. Covers SHA-256, MD5, bcrypt, and when to use each algorithm.

ShareY

Try the free calculator

Use our Password Generator to run the numbers yourself.

What Are Hash Functions

A hash function takes input data of any size and produces a fixed-length output (the hash or digest). The same input always produces the same hash, but even a tiny change in input produces a completely different hash. A good cryptographic hash function has four properties: deterministic (same input gives same output), fast to compute, infeasible to reverse (cannot derive input from hash), and collision-resistant (extremely unlikely for two different inputs to produce the same hash). Hash functions are fundamental to computer science — they power password storage, data integrity verification, digital signatures, blockchain, hash tables, and version control systems like Git.

Common Hash Algorithms

MD5 produces a 128-bit (32 hex character) hash. It is fast but cryptographically broken — collisions have been found, meaning two different inputs can produce the same hash. Do not use MD5 for security purposes; it remains useful for non-security checksums. SHA-1 produces 160-bit hashes and is also considered broken for security. SHA-256 (part of the SHA-2 family) produces 256-bit hashes and is currently the standard for security applications — it is used in TLS/SSL, Bitcoin, and digital certificates. SHA-3 is the newest standard, offering a completely different internal design from SHA-2 as a backup if SHA-2 is ever compromised. For password hashing specifically, use bcrypt, scrypt, or Argon2 — these are intentionally slow to resist brute-force attacks.

Hash Functions for Password Storage

Never store passwords as plain text or with general-purpose hashes (MD5, SHA-256). Use dedicated password-hashing functions: bcrypt adds a random salt and uses a configurable work factor that makes hashing intentionally slow (100 milliseconds or more per hash). scrypt adds memory-hardness, making GPU-based attacks more expensive. Argon2 (the winner of the Password Hashing Competition) is the most modern option, offering configurable time, memory, and parallelism costs. Each hashing function automatically generates a random salt — a unique value prepended to the password before hashing — which ensures that identical passwords produce different hashes. The salt is stored alongside the hash in the database.

Data Integrity and Digital Signatures

Hash functions verify data integrity — downloading a file and comparing its SHA-256 hash to the published hash confirms the file was not corrupted or tampered with during transmission. Git uses SHA-1 (migrating to SHA-256) to uniquely identify every commit, file, and tree in a repository. Digital signatures hash a document and then encrypt the hash with the signer's private key — the recipient decrypts with the public key and compares hashes to verify both authenticity and integrity. HMAC (Hash-based Message Authentication Code) combines a hash function with a secret key to verify both data integrity and authenticity in API authentication and session tokens.

Related Free Tools

Related Articles

Frequently Asked Questions

Can a hash be reversed to find the original input?

Cryptographic hash functions are designed to be irreversible — you cannot mathematically derive the input from the hash. However, attackers use pre-computed tables (rainbow tables) and brute-force attacks to find matching inputs for weak hashes. This is why password hashing uses salts (to defeat rainbow tables) and slow algorithms (to make brute force impractical). For strong hashes like SHA-256, reversing the hash is computationally infeasible.

What is a hash collision?

A collision occurs when two different inputs produce the same hash output. Since hash outputs are fixed-length but inputs can be any size, collisions must theoretically exist. For strong algorithms like SHA-256, finding a collision requires roughly 2^128 operations — effectively impossible with current technology. MD5 collisions can be found in seconds, which is why it is no longer used for security. Collision resistance is what makes hash functions trustworthy for digital signatures and data integrity.

Why not just use SHA-256 for password hashing?

SHA-256 is too fast — modern GPUs can compute billions of SHA-256 hashes per second, allowing attackers to test enormous numbers of password guesses quickly. Password-hashing functions like bcrypt, scrypt, and Argon2 are intentionally designed to be slow (adjustable to take 100 to 500 milliseconds per hash) and memory-intensive, making brute-force attacks millions of times more expensive. Speed is desirable for data integrity but dangerous for password storage.