Masks, feathering and the context window
What a mask actually does
Inpainting is the same denoising loop with one addition. At every step, the parts of the latent outside your mask are overwritten with the correctly-noised version of the original image. Only the inside of the mask is free to change.
That means the region being regenerated is surrounded, at every step, by the real picture. The model is not repairing in isolation; it is completing a scene it can see. This is why inpainting produces results that match lighting and colour without being told to, and why it is a different and far more reliable tool than regenerating the whole image and hoping.
The three settings that decide the result
Mask size and shape. Too tight and the model has no room to place anything; the fix is squeezed into an area the wrong shape. Too loose and you have thrown away good pixels. A useful default is to mask the problem plus roughly half its own width of surrounding area.
Feather or blur. A hard-edged mask leaves a visible seam because the boundary between generated and original falls on a single pixel line. A feather of 4 to 16 pixels blends the transition. This one setting is the difference between a repair that reads and one that announces itself.
Context area — the setting nobody explains. Most implementations do not process the whole image for an inpaint. They crop a region around the mask, scale it to the model's native size, generate, and paste back. The size of that crop is the model's entire view of the scene.
This last one explains the most common inpainting failure. Mask a face in a large image with a tight context crop, and the model sees a face-sized rectangle with no shoulders, no horizon and no light source. It has no idea which way the light falls, so it invents one. Widen the context and the same mask produces a correct result. In WebUI this appears as "only masked padding"; in ComfyUI it is the crop size on the inpaint node. When a repair comes back lit wrong, this is nearly always why.
Why the crop is also a resolution gift
There is a bonus in the crop mechanism worth exploiting deliberately. Because the cropped region is scaled up to the model's native size before generation, a small masked area is being generated at full model resolution and then scaled back down.
A face that occupies seven latent cells in the full image occupies the whole latent grid when inpainted with a tight crop. This is the mechanism behind face-detailer workflows, and it is why inpainting a small element gives dramatically more detail than the same element in the original generation. It is not that the model tries harder. It has sixteen times the cells.
Outpainting is the same thing pointed outwards
Extending an image beyond its borders uses identical machinery: pad the canvas, mask the new area, inpaint with the existing image as context. The failure modes are the same. Extend too far in one pass and the far edge has no context and drifts; extend in steps of 128 or 256 pixels and each step stays anchored.
A practical note that saves a lot of confusion: many models are markedly worse at outpainting downward than in other directions, because photographs are cropped at the bottom far more consistently than at the top, so the training data contains fewer examples of what continues below a frame.
Where inpainting stops being the answer
Inpainting is the right tool for a wrong region. It is the wrong tool for a wrong picture. If the composition is not working, no amount of masked repair will fix it, and you will spend an hour discovering that.
There is also a class of problem inpainting handles badly: anything requiring agreement with a region you are not regenerating. Fixing one earring to match the other means the model must reproduce the other, which it can only see as context. It often gets close and rarely gets exact. For symmetry, the reliable fix is mechanical — copy the good one, flip it, place it, blend — in GIMP, Krita or Photopea, all free.
The general rule that emerges across this module: use the generative tool for texture and content, and use ordinary image editing for geometry and symmetry. Each is far better than the other at its own job, and most of the frustration people report comes from asking one to do the other's work.
The one thing to keep
Masked regeneration replaces only the masked latent while conditioning on the surrounding pixels, so what the model can see around the mask determines whether the repair matches.
Before you move on
An inpainted face comes back correctly rendered but lit from the wrong side. Which setting is the first thing to change?
Pick the one you would defend. Nobody sees your answer.