Skip to content
,

ComfyUI Masks Guide: Create, Edit and Use Masks (Every Node)

8–12 minutes
Woman in a brick-walled loft holding a tablet with a MASKS card, hook mask like a pro

Masks are how you tell ComfyUI “only change this part”. Inpainting, outpainting, regional prompts, background swaps and compositing all depend on them. Yet the mask nodes are some of the least explained in ComfyUI, and a wrong mask is behind many “my inpaint changed the whole image” questions.

This guide covers every core mask node, checked against the ComfyUI source. You’ll learn where masks come from, how to edit them (invert, grow, feather, threshold, combine), how to use them in sampling and compositing, and how to fix the usual mistakes.

TL;DR

  • A mask is a grayscale map: white (1.0) = affected, black (0.0) = left alone. Gray values give partial strength.
  • Quickest mask: right-click a Load Image node → Open in MaskEditor, paint, save. The MASK output is then ready to use.
  • Edit masks with: Invert Mask, Grow Mask, Feather Mask, Threshold Mask and MaskComposite (add, subtract, multiply, and, or, xor).
  • Use masks with: VAE Encode (for Inpainting), Set Latent Noise Mask, Image Composite Masked and Conditioning (Set Mask).
  • Check before sampling: wire the mask into Preview Mask (or Convert Mask to Image → Preview Image) so you can see what ComfyUI sees.

New to ComfyUI? Start with my ComfyUI guide, which covers installing, models and your first workflow.

What a Mask Is in ComfyUI

In ComfyUI a MASK is a single-channel grid of numbers between 0 and 1, the same width and height as the image it belongs to. It has no color. When you preview it, 1.0 shows as white and 0.0 as black.

  • 1.0 (white): the area the next node acts on, such as the part to inpaint.
  • 0.0 (black): the area that stays as it is.
  • In between (gray): partial effect. Soft edges from Feather Mask are gray, which is what makes blends invisible.

The MASK type is separate from IMAGE. You can’t plug a mask into an image input directly. Use Convert Mask to Image or Convert Image to Mask to switch between them.

Where Masks Come From

1. Load Image and the MaskEditor

The Load Image node has two outputs: IMAGE and MASK. The MASK output is built from the image’s alpha (transparency) channel. In the source it is 1 − alpha, so the transparent areas become the white, active part of the mask.

To paint a mask, right-click the Load Image node and choose Open in MaskEditor. Paint over the area you want to change and click Save. ComfyUI stores the painted area as transparency in a copy of the image, so the MASK output now holds your painting.

If the image has no alpha channel and you haven’t painted anything, Load Image outputs an empty 64×64 mask of zeros. That is a common reason an inpaint “does nothing”.

2. Load Image (as Mask)

This node loads a file and turns one channel into a mask. The channel option is alpha, red, green or blue. Use it when you made a black-and-white mask in another app: pick red (any color channel works for a gray image), and white areas become 1.0.

3. Converting an image

  • Convert Image to Mask: takes one channel (red, green, blue or alpha) of any IMAGE. Good for masks made by other nodes, such as a background-removal or segmentation output.
  • Convert Image Color to Mask: turns every pixel of one exact color into 1.0 and everything else into 0.0. The color value is an integer (for example 16777215 for pure white, 0 for black). Useful for flat color maps.

4. Create Solid Mask

Makes a mask of one value at a set size (defaults: value 1.0, 512×512). Combine it with MaskComposite to build rectangles and regions without painting.

5. Masks from custom nodes

Automatic masks, like “every face” or “the person”, come from custom nodes: segmentation (SAM-style) nodes, face detectors in Impact Pack, and background removers. They all output a standard MASK, so everything in this guide still applies.

For a background mask, see my guide to removing backgrounds locally. To install node packs, see ComfyUI Manager.

Editing Masks: The Core Nodes

All of these live in the mask category (double-click the canvas and search the name). Defaults are from comfy_extras/nodes_mask.py.

Node What it does Key settings
Invert Mask Swaps white and black (1 − mask) None
Grow Mask Expands (positive) or shrinks (negative) the mask by pixels expand, tapered_corners (on by default)
Feather Mask Fades the mask edge toward 0 on each side left, top, right, bottom in pixels
Threshold Mask Turns gray values into pure 0 or 1 value (default 0.5)
Crop Mask Cuts out a rectangle of the mask x, y, width, height
Solid Mask New mask of one value value 1.0, 512×512
Preview Mask Shows the mask on the canvas None

Grow Mask: give the model room

A tight mask drawn right on the edge of an object often leaves a visible outline after inpainting. Grow the mask by 8-24 pixels so the model can repaint the border too. Use a negative expand to pull a mask inward, for example to keep a hairline untouched.

Feather Mask: hide the seam

Feathering fades the mask edge so the new pixels blend into the old ones. It matters most when compositing. A good pattern is Grow Mask → Feather Mask: grow first so the soft edge falls outside the object, not inside it.

Threshold Mask: clean up soft masks

Segmentation and background-removal masks often have faint gray noise. Threshold Mask at 0.5 turns anything above into 1.0 and everything else into 0.0. Raise the value to drop more noise, lower it to keep more of the edge.

Combining Masks with MaskComposite

MaskComposite merges a source mask into a destination mask at position x, y. The operation decides how:

  • add: union of both, capped at 1.0. “This area plus that area.”
  • subtract: removes the source from the destination. “The person, minus the face.”
  • multiply: keeps only where both are white. Same result as and for pure black-and-white masks.
  • and / or / xor: logic operations on rounded values. xor keeps areas that are in one mask but not both.

The x and y offsets let you place a small mask (for example a Solid Mask of 256×256) anywhere inside a larger one. That’s how you build rectangular regions with no painting at all.

Using Masks in Sampling

There are three ways a mask changes what the sampler does. Picking the wrong one is the most common masking mistake.

VAE Encode (for Inpainting)

This node encodes the image and blanks out the masked area before sampling. Its grow_mask_by setting defaults to 6 pixels. Because the masked area is wiped, you need denoise 1.0, and the result works best with a dedicated inpainting model. At lower denoise you get a gray smear.

Set Latent Noise Mask

This node keeps the original latent and only tells the sampler which part it may change. The model still sees the original pixels under the mask, so you can use any denoise.

Around 0.4-0.7 gives edits that follow the original shapes and colors; 1.0 repaints freely. This works with normal checkpoints, so it’s the safer default.

Full inpainting settings are in my ComfyUI inpainting guide.

Conditioning (Set Mask)

This applies a prompt to one area of the image. Strength and area settings decide how strongly it applies. It’s the basis of regional prompting, covered in ComfyUI regional prompting.

Outpainting: Pad Image for Outpainting

This node adds empty space to the left, top, right or bottom of an image (in steps of 8 pixels) and outputs a mask for the new area. The feathering setting (default 40) softens the join. Feed both outputs into VAE Encode (for Inpainting).

Compositing Images with a Mask

Image Composite Masked pastes a source image onto a destination image at x, y, but only where the optional mask is white. With resize_source on, the source is scaled to fit the destination first. Latent Composite Masked does the same with latents.

The main use is “paste back”. After inpainting, VAE decoding slightly changes even the unmasked pixels. To keep the original pixels exactly, composite the inpainted image onto the original using the same (feathered) mask. Only the masked area changes, and the rest stays pixel-perfect.

Three Practical Recipes

Recipe 1: Fix one detail without touching the rest

  1. Load Image → Open in MaskEditor → paint the hand, face or object.
  2. MASK → Grow Mask (expand 12) → Feather Mask (8 on every side).
  3. VAE Encode the image → Set Latent Noise Mask with that mask.
  4. KSampler at denoise 0.55, with a prompt describing the fixed detail.
  5. VAE Decode → Image Composite Masked onto the original, using the same mask.

Recipe 2: Change the background, keep the subject

  1. Get a subject mask from a background-removal node.
  2. Threshold Mask (0.5) to clean it, then Invert Mask so the background is white.
  3. Grow Mask by -4 so the edit doesn’t eat into the subject’s edge.
  4. Set Latent Noise Mask → KSampler at denoise 0.9-1.0 with a new background prompt.

Recipe 3: Left and right regions with no painting

  1. Solid Mask value 0.0 at the full image size (the destination).
  2. Solid Mask value 1.0 at half the width (the source).
  3. MaskComposite, operation add, x 0 → left-half mask. Invert Mask → right-half mask.
  4. Use each with Conditioning (Set Mask) for two different prompts.

Troubleshooting

The inpaint changed nothing

The mask is probably empty. Check it with Preview Mask. If you loaded a JPG without painting it in the MaskEditor, there’s no alpha, so the mask is all zeros.

The whole image changed

The mask may be inverted, or you used a plain VAE Encode without Set Latent Noise Mask, so the sampler had no mask at all. Preview the mask, and make sure it reaches the latent.

Gray blob inside the masked area

You used VAE Encode (for Inpainting) with denoise below 1.0. Set denoise to 1.0, or switch to Set Latent Noise Mask.

Visible seam or halo around the edit

Grow the mask a little and feather it, then paste back with Image Composite Masked using the feathered mask. Also see my black image fix if the area comes out black.

Size or shape mismatch error

The mask and image are different sizes, often after you resized the image but not the mask. Resize both the same way, or create the mask after resizing. Outpaint widths must also be multiples of 8.

FAQ

Is white or black the masked area in ComfyUI?

White (1.0) is the area that gets changed. Black (0.0) is protected.

How do I invert a mask in ComfyUI?

Add the Invert Mask node between the mask source and the node that uses it.

Can I use a black-and-white PNG as a mask?

Yes. Load it with Load Image (as Mask) and set channel to red. White areas become the active mask.

What’s the difference between Set Latent Noise Mask and VAE Encode for Inpainting?

Set Latent Noise Mask keeps the original image under the mask and works at any denoise. VAE Encode for Inpainting wipes the area and needs denoise 1.0, ideally with an inpainting model.

Why does my mask look blank in Preview Image?

Preview Image needs an IMAGE. Use Preview Mask, or Convert Mask to Image first.

How much should I grow a mask?

8-24 pixels for most inpaints at 1024px. Grow more for large objects, less for fine details.

Can I make masks automatically?

Yes, with segmentation, face-detection or background-removal custom nodes. They output a normal MASK you can edit with the core nodes.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a brick-walled loft holding a tablet with a MASKS card, hook mask like a pro