A hash function compresses input into a fixed-length digest through a sequence of deterministic rounds; the output changes completely when any bit of input changes.
The internal structure depends on the algorithm, but the external behaviour is uniform. Input is padded to a multiple of the block size, processed block by block through a compression function, and the final state is serialized as the digest. The avalanche effect means that flipping one bit of input flips roughly half the bits of the output, which is what makes the digest look random even for closely related inputs.
graph LR I[Input: any length] --> P[Padding] P --> B[Block 1..N] B --> C[Compression rounds] C --> D[Final state] D --> H[Digest: fixed length] H --> U[Integrity check / identity / index]
Git uses this property to build a Merkle tree of commits. Each commit hashes its tree and its parent hashes, so changing a file in a commit changes every hash above it. A container registry uses the digest as the immutable identifier: nginx@sha256:abc... always points to the same bytes, no matter what the latest tag points to that day. A package manager stores the expected digest next to each artifact and re-checks it at install time.
Choosing and using a hash in practice
Match the algorithm to the threat model
Use SHA-256 or SHA-3 for integrity and content addressing. Use bcrypt, scrypt or Argon2 for passwords. Never use MD5 or SHA-1 for anything new.
Verify at the boundary
Compute the digest when a payload crosses a trust boundary (download, upload, deploy) and compare it to the expected value from a signed source.
Pin the digest, not the tag
In container and package pipelines, deploy by digest, not by mutable tag. A tag can be rewritten; a digest cannot.
Plan for rotation
Every hash algorithm has a lifetime. Track deprecation timelines (MD5 broken, SHA-1 broken, SHA-256 in use, SHA-3 and BLAKE3 rising) and migrate before the pressure is external.