VAE Encode and VAE Encode (for Inpainting) node in ComfyUI
VAE Encode converts a pixel IMAGE into a LATENT for img2img; VAE Encode (for Inpainting) does the same while blanking the masked area so an inpainting model can repaint it.
Node pack: ComfyUI core
Category: Latent
What VAE Encode and VAE Encode (for Inpainting) does
To work from an existing picture, the picture has to enter latent space first. VAE Encode takes an IMAGE (from Load Image or an earlier decode) and the VAE and outputs a LATENT that KSampler can continue from with denoise below 1. That is the whole of img2img in ComfyUI.
VAE Encode (for Inpainting) adds a mask input and a grow_mask_by option: the masked pixels are greyed out before encoding and a noise mask is attached, so a dedicated inpainting checkpoint repaints only that region. For inpainting with a normal checkpoint, use VAE Encode followed by Set Latent Noise Mask instead, which keeps the original content under the mask as a starting point.
Inputs
Name | Type | What it is |
|---|---|---|
pixels | IMAGE | The image to encode. Sizes are cropped to multiples of 8. |
vae | VAE | The VAE of the model you will sample with. |
mask (inpaint variant) | MASK | White = area to repaint. |
grow_mask_by (inpaint variant) | INT | Pixels to expand the mask so edges blend; 6-24. |
Outputs
Name | Type | What it is |
|---|---|---|
LATENT | LATENT | The encoded image (with a noise mask in the inpaint variant) for KSampler latent_image. |
AD

Skip the setup: ComfyUI workflows preinstalled on the cloud
BitVector runs ready-made ComfyUI workflows on its own GPUs. No install, no missing nodes, no red boxes. Open it on your phone or laptop and generate in a minute.
How to use VAE Encode and VAE Encode (for Inpainting)
- Load Image, then VAE Encode with the checkpoint VAE.
- Connect LATENT to KSampler; set denoise 0.4-0.7 for a variation, 0.2-0.35 for a touch-up.
- For inpainting: open the mask editor on Load Image, paint the area, use VAE Encode (for Inpainting) with an inpainting checkpoint, denoise 1.0.
Settings and tips
- Resize the input to the model native size before encoding; a 4000 pixel photo encodes to a huge latent.
- denoise 1.0 on VAE Encode (for Inpainting) is correct: the masked region is meant to be fully regenerated.
- With normal checkpoints prefer VAE Encode + Set Latent Noise Mask and denoise 0.5-0.8 for context-aware fills.
- Image dimensions not divisible by 8 are cropped by a few pixels; pad or resize to avoid shifting.
Troubleshooting VAE Encode and VAE Encode (for Inpainting)
The inpainted region ignores the surroundings and looks pasted in
Why it happens
VAE Encode (for Inpainting) was used with a non-inpainting checkpoint, which cannot see the greyed-out area.
How to fix it
Use an inpainting checkpoint (or a Fooocus/Flux Fill inpaint model), or switch to VAE Encode + Set Latent Noise Mask with denoise under 0.8.
Hard edges around the repainted area
Why it happens
grow_mask_by is 0 or the mask has no feathering.
How to fix it
Set grow_mask_by to 12-24, or blur the mask with a Grow Mask / Feather Mask node before encoding.
Nothing changes in img2img
Why it happens
denoise is very low, or the sampler latent input is still the Empty Latent Image.
How to fix it
Wire the encoded LATENT into KSampler and raise denoise to 0.5 to confirm the pipeline.
Error: expected 4 channels but got 16 (or reverse) when encoding
Why it happens
The VAE is from a different family than the model that will sample the latent.
How to fix it
Encode with the same VAE the model decodes with.
AD

Run this workflow from your phone
Every workflow on this page is preinstalled on BitVector with the models and custom nodes already in place. Pick one, type a prompt, done. Zero setup, nothing to download.
Questions about VAE Encode and VAE Encode (for Inpainting)
What denoise should I use for img2img?
0.3 keeps most of the picture, 0.5 is a balanced remix, 0.75 and above keeps little more than composition and colours.
Can I inpaint without an inpainting model?
Yes: VAE Encode, then Set Latent Noise Mask with your mask, then KSampler at denoise 0.5-0.8.
Related nodes
VAE Decode
ComfyUI core
VAE Decode converts the sampled LATENT into a pixel IMAGE with the VAE; VAE Decode (Tiled) does the same in tiles for very large images.
Load Image
ComfyUI core
Load Image reads a picture from the ComfyUI input folder (or an upload) and outputs an IMAGE tensor plus a MASK taken from the alpha channel, the starting point for img2img, inpainting, ControlNet and IP-Adapter graphs.
Set Latent Noise Mask
ComfyUI core
Set Latent Noise Mask attaches a MASK to a LATENT so the sampler only changes the white area: inpainting and regional regeneration with any normal checkpoint.
KSampler
ComfyUI core
KSampler runs the denoising loop: it takes the model, prompts and a latent and produces the finished latent image, controlled by seed, steps, cfg, sampler, scheduler and denoise.
Load VAE
ComfyUI core
Load VAE (VAELoader) loads a standalone VAE file from models/vae so a checkpoint with a missing or weak VAE decodes clean colours, and so split models like Flux and Wan get their decoder.
AD

Tired of fixing nodes? Let the cloud do it
BitVector keeps hundreds of ComfyUI workflows installed, updated and tested on fast cloud GPUs. No Python, no CUDA errors, no VRAM limits. Works from any browser.
More ComfyUI nodes
CLIP Text Encode (Prompt)
ComfyUI core
CLIP Text Encode turns a text prompt into CONDITIONING using the model text encoder. One node holds the positive prompt, a second one the negative prompt.
ComfyUI Manager
ComfyUI-Manager
ComfyUI Manager is the extension that installs, updates and fixes custom node packs and models from inside the interface, resolves missing nodes in imported workflows and snapshots your setup.
Load Checkpoint
ComfyUI core
Load Checkpoint (CheckpointLoaderSimple) opens a .safetensors or .ckpt model file and hands out the three parts every workflow needs: the diffusion MODEL, the CLIP text encoder and the VAE.
Save Image
ComfyUI core
Save Image writes the IMAGE tensor to ComfyUI/output as a PNG, with the whole workflow embedded in the file metadata so the picture can be dragged back into ComfyUI to restore the graph.
Empty Latent Image
ComfyUI core
Empty Latent Image creates the blank latent canvas (width, height, batch_size) that text-to-image sampling starts from; dimensions must be multiples of 8 and match the model family.
Load LoRA
ComfyUI core
Load LoRA (LoraLoader) applies a LoRA file to the MODEL and CLIP with separate strengths, so a style, character or concept can be added to any checkpoint without merging.

Model
Trends
.ai
© ModelTrends.ai
|
Made in Japan
|
© 2026