Toolyard

What Is a Hash? MD5, SHA-1 and SHA-256 Explained

A fingerprint for data

A hash function takes any input (a word, a document, a 4 GB video) and turns it into a short, fixed-length string called a hash, digest or checksum. The same input always gives the same hash, and even a tiny change gives a completely different one:

InputSHA-256 hash
hello2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Hello185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
hello!ce06092fb948d9ffac7d1a376e404b26b7575bcc11ee05a4615fef4fec3a308b

One capital letter or one exclamation mark changes every character of the result. Try it yourself in the Hash Generator.

What makes a good hash function

  • Deterministic: the same input always produces the same hash, on any computer.
  • One-way: you cannot work backwards from the hash to the input.
  • Collision-resistant: it should be practically impossible to find two different inputs with the same hash.
  • Fast to compute for checksums, which is useful, and also why fast hashes are wrong for passwords (more on that below).

Hashing is not encryption

Encryption is two-way: with the key, you get the original back. A hash has no key and cannot be reversed. It only lets you check whether something matches. Base64 is different again: it is just an encoding, and anyone can decode it.

The common algorithms

AlgorithmLengthStatus
MD5128 bits (32 hex characters)Broken since 2004; fine only for spotting accidental corruption
SHA-1160 bits (40 hex characters)Broken: the first real collision was published in 2017
SHA-256256 bits (64 hex characters)Safe; the standard choice today
SHA-512512 bits (128 hex characters)Safe; often faster than SHA-256 on 64-bit computers

Here is the word hello in each:

  • MD5: 5d41402abc4b2a76b9719d911017c592
  • SHA-1: aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
  • SHA-256: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

What "broken" means for MD5 and SHA-1

For MD5 and SHA-1, researchers can deliberately create two different files with the same hash. An attacker could use that to swap a harmless file for a malicious one with a matching checksum, or forge a signed document. Neither is broken in the sense of being reversible, and random corruption still changes the hash, so an MD5 checksum still catches a download that broke off halfway. It just cannot prove nobody tampered with the file.

SHA-256 and SHA-512 belong to the SHA-2 family, published in 2001, and no practical attack on them is known. SHA-3, standardised in 2015, is a different design kept as a backup.

Where hashes are used

  • Checking downloads: developers publish the SHA-256 of their files; if yours matches, it is identical. See how to verify a checksum.
  • Digital signatures and HTTPS certificates: the document or certificate is hashed, and the hash is signed.
  • Git: every commit and file is identified by its hash. Git has long used SHA-1 and has added support for SHA-256.
  • Bitcoin and other blockchains: blocks are chained together with SHA-256.
  • Finding duplicate files: two files with the same SHA-256 are the same file.

Hashes and passwords

Websites should never store your password, only a hash of it; when you log in, they hash what you type and compare. But SHA-256 is the wrong tool here: it is so fast that an attacker with a leaked database can try billions of guesses per second. Passwords need slow, salted hashing designed for the job, such as bcrypt, scrypt or Argon2. A salt is a random value added to each password before hashing, so two people with the same password get different hashes.

Try it

The Hash Generator calculates MD5, SHA-1, SHA-256, SHA-384 and SHA-512 of any text or file at once, in your browser, and can compare them against a published checksum.

Tools in this guide

More guides

How to Open HEIC Files on WindowsHow to Reduce PDF File SizeHow to Remove Location Data from PhotosHow to Extract Audio from a VideoHow to Make a Wi-Fi QR CodeHow to Sign a PDFHow to Verify a File Checksum (SHA-256)PNG vs JPG vs WebP: Which Image Format to UseHow to Merge PDF FilesHow to Copy Text from an ImageHow to Convert JPG to PDFHow to Convert a PDF to JPGHow to Split a PDF or Extract PagesHow to Rotate a PDF PermanentlyHow to Add Page Numbers to a PDFHow to Watermark a PDFHow to Convert HEIC to JPG on a MacHow to Convert WebP to JPGHow to Reduce Image File SizeHow to Convert a Video to GIFHow to Convert WAV to MP3How to Create a Strong PasswordHow to Convert Celsius to FahrenheitGB vs GiB: Why Your Drive Shows Less SpaceHow to Calculate PercentagesHow to Calculate the Number of Days Between Two DatesWhat Is a Unix Timestamp?How to Compare Two Text FilesHow to Count Words in a DocumentHow to Scan a QR Code from a Screenshot or ImageHow to Compress a Photo to 20 KB (or Any Size)How to Remove the Background From a PhotoHow to Test Your MicrophoneHow to Check a Screen for Dead PixelsHow to Record Your ScreenHow to Make a Ringtone for iPhoneHow to Compress a Video to Send ItHow to Remove a Password From a PDFHow to Password Protect a PDFHow to Fill In a PDF FormHow to Convert a PDF to WordHow to Blur a Face in a PhotoHow to Calculate Your BMIHow to Calculate a Mortgage PaymentHow to Schedule a Meeting Across Time ZonesWhat Is a Cron Expression?How to Reverse Complement a DNA SequenceHow to Translate DNA to ProteinHow to Convert GenBank to FASTAHow to Find Restriction Sites in a DNA SequenceHow to Align Two DNA or Protein SequencesHow to Design and Check PCR PrimersHow to Calculate Molar MassHow to Balance a Chemical EquationHow to Make a Solution of a Given MolarityHow to Calculate a Dilution (C1V1 = C2V2)How to Calculate pHHow to Calculate DNA Concentration From A260How to Calculate Insert Amount for a LigationHow to Convert RPM to g (RCF)How to Count Cells With a HemocytometerHow to Use a Punnett SquareHow to Make a Budget With the 50/30/20 RuleDebt Snowball vs Debt AvalancheHow Much Do I Need to Retire?How to Convert Salary to Hourly PayProfit Margin vs MarkupHow to Calculate VAT and Sales TaxHow to Make an InvoiceHow Much House Can I Afford?How to Read Resistor Color CodesHow to Choose a Resistor for an LEDHow to Calculate Voltage Drop in a CableHow Much Concrete Do I Need?How Much Paint Do I Need?How to Calculate a SubnetSignificant Figures Rules