Image Hash Calculator

Same file, same picture, or just similar: three answers.

  • File and visual hashes
  • Compare two pictures
  • Files stay local
Two printed photographs of the same landscape lying side by side on a wooden desk under a magnifying glass, with no people in view

The guide

A file hash asks whether the bytes match; a picture hash asks whether it looks the same

Two kinds of fingerprint answer two different questions about a picture, and most of the trouble starts when one of them is trusted to answer the other.

  • 122 of 256 SHA-256 bits that flip when the text abc becomes abd
  • 64 bits in each of the three simple picture hashes
  • 1 bit moved in the difference hash after a JPEG re-save of the sample
  • 38 of 64 difference hash bits changed by mirroring the sample
  • 10 bits rule-of-thumb limit for calling two pictures a variation
Read the full guide Fold the guide 7 min · 18 sources

Save a photograph twice and you have two files. To a person they are one picture. To a computer they may share almost no bytes. Which of those two views a hash takes is the whole subject.

The argument here is simple. A file hash and a picture hash are opposite tools, built on opposite principles, and each fails badly at the other’s job. A file hash is designed so that the smallest change wrecks the result. A picture hash is designed so that small changes leave the result alone. Neither design is a flaw.

A fingerprint of the bytes

A hash function takes a message of any length and returns a short value of fixed length. MD5 returns 128 bits. The Secure Hash Standard defines a family whose outputs run from 160 to 512 bits, among them SHA-1, SHA-256, SHA-384 and SHA-512. The input may be a single letter or a film; the output is the same size either way.

What makes such a function useful is stated plainly in the standard: any change to a message will, with a very high probability, result in a different message digest. Take the three letters abc and their SHA-256 value, then change the last letter so the text reads abd. The two digests differ in 122 of 256 bit positions, which is close to the half you would expect from two unrelated strings of coin flips. One changed letter, and nothing recognizable survives.

That scrambling is the point, not a side effect. A digest that moved only a little when the input moved a little would leak which inputs are near each other, and would let someone steer toward a target. The properties expected of an approved function are that nobody can feasibly find an input for a chosen output, and nobody can feasibly find two inputs with the same output. Both depend on the output giving no hint of closeness.

Functions age, though. MD5 was published in 1992 with the conjecture that producing two messages with the same digest was infeasible. By 2006 a collision could be found in about one minute on a notebook computer, and the guidance now is blunt: MD5 is no longer acceptable where collision resistance is required. SHA-1 followed. In February 2017 two different PDF files with the same SHA-1 value were published, after roughly nine quintillion computations, and NIST has since said SHA-1 should be phased out by the end of 2030.

A broken function is still good for honest mistakes. A cyclic redundancy check makes no claim to security at all, yet every chunk of a PNG file carries one so that a decoder can notice data corrupted in transit, and the gzip format uses the same polynomial. MD5 and SHA-1 catch a flipped bit or a truncated download just as well as they ever did. What they can no longer do is stand up to someone who is trying to fool them.

Why a picture needs a different question

Now ask a file hash whether two pictures are the same. It will say no for a photograph and its re-saved copy, no for a resized copy, no for the same image as PNG and as JPEG. Each answer is correct about the bytes and useless about the picture. The avalanche that protects a signature destroys any sense of likeness.

A perceptual hash turns the design upside down. It throws away nearly everything in the picture, keeps a crude outline of where the light and dark areas sit, and writes that outline as a short string of bits. Pictures that look alike should give strings that are nearly equal. Closeness, the very thing a cryptographic function hides, is here the only thing that matters.

The three simplest versions each produce 64 bits, and all three begin the same way: shrink the picture until detail is gone, and drop the color. Shrinking removes the fine texture that compression and resizing disturb. Gray is commonly taken as a weighted sum in which green counts most, 0.299 of red plus 0.587 of green plus 0.114 of blue, the luma formula printed in the JPEG file interchange format.

Three small recipes

The average hash, as Neal Krawetz described it in 2011, crushes the picture to eight by eight cells without regard to its proportions, converts to gray, takes the mean of the 64 values and writes one bit per cell: above the mean or not. It is quick and easy to follow. Its weakness, by the same account, is that adjustments to gamma or to the color histogram move the mean and flip bits.

The difference hash, which Krawetz credits to a suggestion from David Oftedal and wrote up in 2013, looks at neighbors instead of an overall level. The picture is reduced to nine cells across and eight down, and each bit records whether a cell is darker than the one to its right. Nine cells give eight comparisons per row, and eight rows give 64 bits. It tracks the direction of brightness changes, so making the whole picture brighter leaves it mostly alone.

The third recipe leans on the discrete cosine transform, the same mathematics that sits inside JPEG. The transform re-expresses a block of pixels as a sum of cosine waves, and for ordinary images most of the information collects in a few low-frequency terms. The hash reduces the picture to 32 by 32 gray cells, transforms it, keeps only the eight by eight block of lowest frequencies and compares each term with their average. A 2010 thesis by Christoph Zauner, which benchmarked functions of this kind, describes a variant that uses the median instead.

Comparison is the same for all three. Count the bit positions in which two hashes differ. That count is the Hamming distance, the number of bits that would have to change to turn one string into the other. Zero means the hashes agree. A count near 32 is what two unrelated 64-bit strings would give.

Where to draw the line is a matter of experience, not of standards. Krawetz’s working rule is that zero indicates a likely match, that anything from one up to 10 bits may be a variation of the same picture, and that more than 10 probably means a different picture. Those figures come from one practitioner’s collection. They are a rule of thumb, and anyone relying on them should measure their own material first.

What one picture shows

Here is a case to reproduce. The tool opens with a sample landscape drawn in code, 480 by 320 pixels: a sky, a sun, two ranges of hills and a lake. Its difference hash reads fdfcfcfc1cf160ff. Press the button that makes picture B a JPEG copy of picture A at quality 80, and compare.

In a test run in Chromium the copy came to 9,067 bytes, and every file hash was different, as it must be. The average hash and the DCT hash did not move at all. The difference hash became fdfcfcfc1cf1e0ff: one hex digit went from 6 to e, which is 0110 against 1110, so exactly 1 bit changed. The mean pixel difference between the two was about 1.1 levels out of 255. Another browser’s JPEG encoder will give other bytes and perhaps another bit or two.

Then run the bench on the same sample. Halving the size changed no bits in any of the three hashes. Trimming five percent from each edge changed 3, 4 and 6 bits. Mirroring changed 38 of 64 bits of the difference hash, more than chance would, because a mirror reverses every left-to-right comparison. A quarter turn left about half the bits of every hash changed. The hashes ride out re-saving and resizing; they do not survive a picture being flipped, turned or cut differently.

Flat areas deserve a warning of their own. Give the same sample a sky that is perfectly even from left to right and neighboring cells become exactly equal, so the difference hash records ties. Re-saving breaks those ties at random; in one such test 15 bits moved at a single quality setting. Drawn graphics, screenshots and scans with large even areas behave this way far more than photographs do.

What these numbers cannot carry

Two programs will rarely agree to the bit. The recipes leave open how the picture is shrunk, which gray weights are used and what happens on a tie, and decoders differ before any of that begins. Krawetz tells readers who reimplement his descriptions that a disagreement of three to five bits with his values is close enough. A browser adds its own layer: a canvas hands back pixel values in a named color space, sRGB when that is what was asked for, and its lossy encoder is the browser’s own, steered only by a quality between 0 and 1. Hashes are comparable only when the same program made both.

A match proves nothing. Sixty-four bits drawn from a thumbnail cannot identify a picture, its author or anyone in it; unrelated images sometimes land close together, and Krawetz reports the average hash matching ten times more wrong pictures than right ones in one of his searches. The reverse failure is easy to arrange on purpose. Researchers who attacked perceptual hashing reported altering more than 99.9 percent of images so that they escaped detection while their content was preserved.

So the honest uses are modest ones. A file hash tells you whether a download arrived intact, or whether two files are byte for byte the same, and for that question SHA-256 is the dependable choice. A picture hash is a sorting aid: it pulls likely duplicates out of a large folder so that a person can look at them. It is not evidence, and it is never a security control. One note for anyone computing them in a browser: the built-in digest call has no streaming form, so the whole file has to sit in memory first.

Sources

Every source consulted for this guide. Links checked October 4, 2026.

  1. RFC 1321: The MD5 Message-Digest Algorithm RFC Editor
  2. RFC 6151: Updated Security Considerations for the MD5 Message-Digest and the HMAC-MD5 Algorithms RFC Editor
  3. FIPS 180-4, Secure Hash Standard (SHS) NIST Computer Security Resource Center
  4. Cryptographic hash function - Glossary NIST Computer Security Resource Center
  5. NIST Retires SHA-1 Cryptographic Algorithm National Institute of Standards and Technology
  6. Announcing the first SHA1 collision Google Online Security Blog
  7. RFC 1952: GZIP file format specification version 4.3 RFC Editor
  8. Portable Network Graphics (PNG) Specification (Third Edition) World Wide Web Consortium
  9. Looks Like It The Hacker Factor Blog (Neal Krawetz)
  10. Kind of Like That The Hacker Factor Blog (Neal Krawetz)
  11. Implementation and Benchmarking of Perceptual Image Hash Functions Christoph Zauner (master's thesis, Hagenberg, 2010)
  12. Hamming distance NIST Dictionary of Algorithms and Data Structures
  13. Discrete cosine transform Wikipedia
  14. JPEG File Interchange Format, Version 1.02 Eric Hamilton, C-Cube Microsystems (hosted by the World Wide Web Consortium)
  15. Adversarial Detection Avoidance Attacks: Evaluating the robustness of perceptual hashing-based client-side scanning USENIX Security Symposium 2022
  16. SubtleCrypto: digest() method MDN Web Docs
  17. HTMLCanvasElement: toBlob() method MDN Web Docs
  18. CanvasRenderingContext2D: getImageData() method MDN Web Docs