A hash function reduces any input to a fixed-length fingerprint. The same input always produces the same output, a different input almost certainly produces a different output, and you cannot work backwards from the fingerprint to the original. That makes hashes useful for comparing things without storing them, and for detecting whether data changed.

The everyday uses are verifying that a downloaded file matches its published checksum, generating a cache key or an ETag from content, checking whether two blobs of text are identical without diffing them, and computing the digest that a webhook signature or API request signature is built on.

Which algorithm to use depends entirely on whether an attacker is involved. MD5 and SHA-1 are both cryptographically broken: it is practical to construct two different inputs with the same hash, which has been demonstrated with real certificates and real documents. They are fine as non-adversarial checksums and you will keep meeting them in older systems, but they must not be used for signatures, integrity guarantees, or anything security-relevant. Use SHA-256 or better for that.

The SHA family here is computed with the Web Crypto API built into your browser, which is both faster and better audited than any bundled JavaScript implementation. MD5 is not offered by Web Crypto, precisely because it is broken, so it is computed by a small implementation included on this page.

One thing hashes are not is a way to store passwords. A raw SHA-256 of a password is far too fast to compute, which is exactly what an attacker with a stolen database wants. Password storage needs a deliberately slow, salted function such as bcrypt, scrypt or Argon2.