What is a Mask?

A mask is a black-and-white image that tells a process which parts of an image to include or exclude.
- White: Process (Apply)
- Black: Do not process (Protect)
- Gray: Adjusts the strength (*depends on the feature)
Masks in AI

In image generation AI, masks are mainly used for Inpainting, which redraws only part of an image.
The AI regenerates only the white areas and leaves the black areas as they were in the original image.
Regular Inpainting can't handle gray (semi-transparent) masks, so they get treated as either white or black anyway.
If you want to use a gradient mask to, say, "change things just slightly," you need a special technique called Differential Diffusion.
What is an Alpha Channel?

Regular images represent color with three channels, R (Red), G (Green), and B (Blue), but images with a transparent background (such as PNGs) also contain a channel called A (Alpha). This is the channel that holds transparency.
How ComfyUI Handles Transparent Images
This is where it gets a little confusing: Stable Diffusion itself can't work with transparent images directly. So when you load a transparent PNG into ComfyUI, it is split internally into two parts: an RGB image and a mask.

Let's look at the output of the Load Image node.
- IMAGE (RGB)
- The alpha channel is dropped, so transparent areas are filled with black.
- MASK
- The alpha channel (transparency) is extracted.
- In ComfyUI, transparent areas become white.
How This Differs from Other Software

Many apps create masks with transparent areas as black, so if you're used to image editors like Photoshop or Affinity Photo, this may be confusing. Just think of it as a different convention.
It's easier to follow if you think of it as a flow: the white part of the mask is what gets processed → the alpha channel is applied to the white part, making it transparent.
Joining and Splitting RGBA
So what if you want to save the result with a transparent background again after processing?

🟨Join Image With Alpha Node
Combines an IMAGE (RGB image) and a MASK into a single RGBA image (transparent image).
Connect it to a Save Image node to save it as a transparent PNG.
🟪Split Image With Alpha Node
The reverse: this node splits an RGBA image into RGB and MASK.
🚨 Error Trap: Mixing Up RGBA and RGB
On ComfyUI wires, RGB images (3 channels) and RGBA images (4 channels) both travel as the same IMAGE type. You can't tell them apart by looking.
But the AI parts (KSampler and VAE) basically only accept 3-channel RGB images.
So if you accidentally connect an RGBA image from Join Image With Alpha to something like VAE Encode, you'll get an error like this:
RuntimeError: Given groups=1, ... expected input to have 3 channels, but got 4 channels instead
If ComfyUI yells at you with "I expected 3 channels but got 4!", check whether your image turned into RGBA somewhere along the way.
Custom nodes for things like background removal sometimes output RGBA without warning.