/ALGORITHM · FLOYD-STEINBERG

Floyd-Steinberg Dithering

The short answer

Floyd-Steinberg dithering is the error-diffusion algorithm published by Robert Floyd and Louis Steinberg in 1976, and it is still the default almost everywhere. Each pixel is rounded to the nearest available colour, and the error that rounding introduced is pushed onto four neighbours that have not been drawn yet, in the ratio 7, 3, 5, 1 over sixteen. Because the weights add up to exactly 1, nothing is thrown away, which is why it holds more detail than any of the alternatives and why its speckle looks slightly organic rather than patterned.

A photograph dithered with the Floyd-Steinberg algorithm in one-bit black and white, showing its fine irregular speckle
The same photograph, dithered with this algorithm at one-bit mono.

The kernel

The whole algorithm is this table. X is the pixel just drawn, and the fractions are how much of its error each neighbour absorbs:

        X   7/16
  3/16 5/16 1/16

Two details matter more than people expect. The first is that the error is carried in full precision, not rounded per step, so it accumulates across a run of similar pixels and eventually forces a flip. That accumulation is what creates texture in a flat area instead of a solid block. The second is that it only ever pushes error forward, to pixels not yet processed, which is what makes a single left-to-right, top-to-bottom pass sufficient.

Why it is still the default

Not, as is often claimed, because it conserves the full error. Stucki, Jarvis and Sierra all conserve it too: their weights sum to exactly 1 just as these do. Only Atkinson deliberately throws error away. What actually distinguishes Floyd-Steinberg is that it achieves full conservation with the smallest kernel of the family, four neighbours against Stucki's twelve. That makes it roughly three times cheaper per pixel, and it keeps the error local, so edges stay crisp rather than being smeared across two rows. You pay for that locality with the worm artefact below. If you are dithering because you have to rather than because you want the look, this remains the correct default.

The worm artefact, and what to do about it

The one real complaint about Floyd-Steinberg is worming: in smooth gradients the dots line up into short diagonal chains that the eye picks out as texture crawling across the image. It happens because the error always flows in the same direction on every row. Three fixes, in order of how often they work:

The algorithm, in about fifteen lines

Worth seeing written out, because the two things people get wrong are both visible here: the error is carried at full precision rather than rounded per step, and it only ever flows to pixels that have not been drawn yet.

for (let y = 0; y < h; y++) {
  for (let x = 0; x < w; x++) {
    const i   = (y * w + x);
    const old = buf[i];
    const nw  = nearest(old);        // snap to the palette
    buf[i]    = nw;
    const err = old - nw;            // keep the remainder in full precision

    if (x + 1 < w)            buf[i + 1]     += err * 7 / 16;
    if (y + 1 < h) {
      if (x > 0)              buf[i + w - 1] += err * 3 / 16;
                              buf[i + w]     += err * 5 / 16;
      if (x + 1 < w)          buf[i + w + 1] += err * 1 / 16;
    }
  }
}

Two notes that save an afternoon. Keep buf as floats, not bytes: clamping to 0–255 after every pixel destroys the accumulation that makes the texture. And do the palette snap on the accumulated value, not the original, which is why the read happens after the previous pixels have already written into this one.

When Floyd-Steinberg is the wrong answer

It is the default, not the universal choice. Four cases where something else wins:

Floyd-Steinberg against the alternatives

Try it on your own image

Floyd-Steinberg is already selected below. Drop a photo in and switch the algorithm to compare the same source across all seven. Everything runs in your browser, nothing is uploaded.

Drop an image here or click to choose one. The file is opened by this page and never uploaded.
Floyd-Steinberg

Controls

4
100
0

This runs the same kernels and palette values as the full editor. Switch the algorithm above to compare Floyd-Steinberg against the others on your own image.

Frequently asked questions

What is Floyd-Steinberg dithering?
An error-diffusion dithering algorithm published by Robert Floyd and Louis Steinberg in 1976. Each pixel is rounded to the nearest available colour and the resulting error is distributed to four not-yet-drawn neighbours in the ratio 7, 3, 5 and 1 sixteenths. It is the most widely used dithering algorithm and the default in most image software.
What is the Floyd-Steinberg matrix?
Seven sixteenths to the pixel on the right, then on the row below, three sixteenths down-left, five sixteenths directly below and one sixteenth down-right. The four weights sum to exactly 1, so no error is discarded.
Why does Floyd-Steinberg produce worm patterns?
Because the error always flows in the same direction on every row, so in smooth gradients the dots align into short diagonal chains. Serpentine scanning, which reverses direction on alternate rows, removes most of it. Switching to a wider kernel such as Stucki also helps.
Floyd-Steinberg or Atkinson, which is better?
Neither is better in general. Floyd-Steinberg conserves the full error and keeps detail in highlights and shadows, which makes it the right default for a faithful reduction. Atkinson discards a quarter of the error, which blows out highlights and crushes shadows, and that is why it reads as a deliberate 1-bit style.
Is Floyd-Steinberg still used today?
Yes. It remains the default error-diffusion method in most image editors, GIF and PNG palette reduction, e-ink rendering and thermal printing, because it achieves full error conservation with the smallest kernel in the family, four neighbours rather than twelve, which keeps it cheap and keeps edges local.
Can I apply Floyd-Steinberg dithering online for free?
Yes. The tool above runs it in your browser with no signup and no upload. Compare it against Stucki, which conserves the same full error over twelve neighbours, to see what the wider kernel buys and costs.

Floyd-Steinberg is one of fifteen dither algorithms in the engine. The complete guide to dithering puts the error-diffusion family side by side with the ordered one, and the dither tool runs all of them on your own image with the full palette set.