Tools like Stable Diffusion and DALL·E can turn a sentence into a detailed picture in seconds. Under the hood, most of them rely on the same surprisingly simple idea: learn how to remove noise, then start from pure noise and keep removing it.
This post walks through how that works, using pictures first and maths only where it helps.
The big idea: learn to clean up noise
Take any photo, say of a cat, and sprinkle a little random static over it. Do that again, and again. After enough rounds the photo is gone and all that is left is noise, like an old TV with no signal.
Going that way is easy and needs no intelligence at all. Going the other way, from static back to a picture, is the hard part, and that is exactly what a diffusion model learns to do. It never learns to make a picture in one go. It only learns to make a noisy picture slightly less noisy.
Once a model can take one small step from noisier to cleaner, you can chain hundreds of those steps together. Start from pure static, step, step, step, and an image appears. Because the starting static is random, you get a different image every time.
Step one: destroying images on purpose
During training, we take real images and add noise to them according to a fixed recipe, called a noise schedule. Early steps add only a whisper of noise; by the last step (often step 1,000) the image is indistinguishable from pure static.
A handy shortcut: we never need to add noise a thousand times in a row. There is a formula that jumps straight to any step by mixing the clean image with fresh noise :
You can read it as a slider. The number says how much of the original image survives at step : close to 1 at the start, so it is mostly image; close to 0 at the end, so it is mostly noise.
Step two: learning to guess the noise
Here is the clever part. Instead of asking the network “what should the clean image look like?”, we ask an easier question: “which noise was added to this image?” If it can answer that, we can subtract the noise and get a cleaner image.
The network is usually a U-Net or a transformer. It is also told how noisy the image is (the step number), and optionally a description of what the image shows, such as a text prompt. Training simply measures how far its guess is from the real noise, and nudges it to do better:
In words: average, over many images, noise samples and steps, the squared gap between the true noise and the network’s guess . The is the optional description, such as text, a class label, a pose or another image.
Step three: making a brand new image
To generate, we start from pure random noise, , and repeat: ask the network for its noise guess, remove a bit of it, move to the next step. The early steps decide the big picture (where the cat sits, roughly what colours); the late steps add edges, texture and fine detail.
The original method (DDPM) needs many steps, so it is slow. A later method (DDIM) showed the same trained network can take far fewer, larger steps. Modern samplers keep playing with the same trade-off: fewer steps are faster, more careful steps can look better.
Steering it with a prompt
Text-to-image tools turn your prompt into numbers and feed them to the network at every step, so its noise guesses lean toward images that fit the description.
A trick called classifier-free guidance makes the steering stronger. The network makes two guesses, one with your prompt and one without, and the tool pushes further in the direction where they differ. Turn that knob up and images follow the prompt more literally; turn it too far and they become flat, over-saturated and all alike.
Why most models work in a smaller space
Running hundreds of denoising steps on every pixel of a large image is expensive. Latent diffusion first compresses the image into a much smaller grid of numbers using an encoder, does all the denoising there, and only at the end turns the result back into pixels with a decoder.
The compression throws away detail you would barely notice while keeping the layout and meaning of the image, which makes training and generation far cheaper. The catch: anything the compression threw away can never come back, so the decoder sets a ceiling on how sharp the final image can be.
What can go wrong
- It is slow by design. Each step depends on the one before, so generating an image takes many passes through the network, not one.
- A prompt is a nudge, not a contract. Guidance steers toward likely images; it does not guarantee the right number of fingers, exact text or correct facts.
- The data shows through. Biases, gaps and duplicated images in the training set can reappear in what the model makes, sometimes as near-copies.
- Good scores are not the whole story. Common metrics check that images look realistic overall, not that they are accurate, original or safe.
The mental model
A diffusion model is a very good noise remover. Training teaches it to clean up a slightly noisy image at every level of noise. Generation chains those small clean-ups together, turning random static into a picture one step at a time.
Everything else, from samplers and guidance to latent spaces and prompts, is about where that journey happens and how firmly we steer it.