kb/data/developer.mozilla.org/en-US/docs/Glossary/Hash_function-0.md

12 KiB

title chunk source category tags date_saved instance
Hash function - Glossary | MDN 1/3 https://developer.mozilla.org/en-US/docs/Glossary/Hash_function reference web, html, css, javascript, documentation 2026-05-05T05:33:48.742272+00:00 kb-cron

MDN HTML HTML: Markup language

HTML reference

HTML guides

Markup languages

CSS CSS: Styling language

CSS reference

CSS guides

Layout cookbook

JavaScriptJS JavaScript: Scripting language

JS reference

JS guides

Web APIs Web APIs: Programming interfaces

Web API reference

Web API guides

All All web technology

Technologies

Topics

Learn Learn web development

Frontend developer course

Learn HTML

Learn CSS

Learn JavaScript

Tools Discover our tools

About Get to know MDN better

Blog

  1. Glossary
  2. Hash function

Hash function

A hash function is a function that takes a variable-length input and produces a fixed-length output, also called a digest (or just a "hash"). Hash functions should be quick to compute, and different inputs should as far as possible produce different outputs (this is called collision-resistance). Hash functions have both cryptographic and non-cryptographic uses. Outside cryptography, for example, hash functions can be used to generate the keys for an associative array such as a map or a dictionary. The digest() function of the SubtleCrypto interface makes various hash functions available to web applications.

In this article

Cryptographic hash functions

In cryptography, hash functions have many applications, including digital signatures, and message authentication codes. Not all hash functions are appropriate for cryptography. To be used for cryptography, a hash function must be:

  • quick to compute
  • one-way: given the output, it should be impractical or impossible to regenerate the original input
  • tamper-resistant: any change to the input leads to a different output
  • collision-resistant: it should be impractical to find two different inputs that produce the same output

The hash functions most commonly used in cryptography are from the SHA-2 (Secure Hash Algorithm 2) family, whose names are "SHA-" followed by the length of the output digest in bits: for example, "SHA-256" and "SHA-512". SHA-2 is the successor to the SHA-1 algorithm, which is no longer considered secure and should not be used in cryptography. Note that the MD5 algorithm is also considered insecure.

See also