How Do Diffusion Models Work, Basically?
How diffusion models learn to remove noise, then make pictures from static, with the cost trade-off explained simply for your AI interview.
In short
A diffusion model learns to remove noise. In training it damages real photos a little at a time and learns to undo each step. To make a new picture, it starts from random static and cleans it up step by step, guided by your text prompt.
13 min readIntermediateCommon · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
A diffusion model learns to remove noise. In training, I take real photos, add noise in small steps until they are pure static, and teach the network to guess the noise at each step. To make a new picture, it starts from random static and removes the noise step by step, guided by a text prompt. It works very well, but each picture takes many network runs, so teams work hard to make those runs cheaper.
A diffusion model is a network that learns to remove noise. Noise is random graininess, like the speckle on a photo taken in a dark room. A model that is good at cleaning noise can start from pure static and clean its way to a picture. Ho and colleagues described this in 2020 as a chain of small steps, each one undoing a bit of damage.
Training runs the damage first. A real photo gets a little noise added, again and again, until nothing of the picture is left. The network sees a noisy version and a step number, and learns to guess the noise that was added. Nothing new is painted during training. The network only learns to undo one small step at a time.
Making a picture starts from random static and runs the clean-up many times. A text prompt is turned into numbers and fed into the network at each step, so the clean-up is steered toward the words. The catch is cost. Each image needs many network runs, one after another. Latent diffusion helps by doing those runs on a smaller, compressed version of the image.
So my short answer is that the model learns the reverse of a fixed damage process. Where it is strong, the images are very good. Where it is weak, it is slow and expensive, so cost is a real design question for any team that uses it at scale.
What is a diffusion model, in plain words?
A diffusion model is a network that learns to remove noise. Noise is random graininess, like the speckle on a photo taken in a dark room. Once a model is good at cleaning noise, it can start from pure static and clean its way to a picture.
Think of a document conservator at a records office. She has seen thousands of water-damaged files. Shown a smudged page, she learns to guess what the page looked like before the damage, one layer at a time. A diffusion model learns the same kind of repair, but with pixels instead of ink.
Now a real case. A retailer's catalogue team needs a plain studio backdrop behind thousands of product shots. A diffusion model can build each backdrop from static, guided by a text prompt that describes the look.
Key words
- Noise
- Random speckle added to an image, like grain on a photo taken in the dark.
- Clean-up step
- One pass where the model removes a little of the noise.
- Latent space
- A compressed, smaller version of the image, where each step is cheaper to run.
- Text prompt
- The words you give the model, which steer what the picture shows.
- Sampling
- Making a new image by running the clean-up steps from random static.
How does training work, step by step?
Training never paints a picture. It damages real photos on purpose, then teaches the network to undo one small step of the damage.
How a diffusion model is trained
Real photo
one picture from the training set
Noisy version
a little static added, repeated
Neural network
guesses the noise that was added
Adjust its settings
a closer guess next time
- 1A real photo is damaged a little on purpose, one step at a time.
- 2The network sees the damaged picture and the step number.
- 3Its guess is compared with the noise that was really added.
- 1
Take a real photo
A picture from the training set, the kind of image the model should learn to match.
- 2
Add a little noise
A fixed recipe adds a small amount of random noise. Repeat it until the photo is pure static. Nothing is learned in this part.
- 3
Ask the network to guess
It sees the noisy picture and the step number, and guesses the noise that was added.
- 4
Correct the guess
The guess is compared with the real noise. The network's settings (its weights) are nudged so the next guess is closer.
Here is the damage part on its own, in a few lines of Python. A made-up strip of 8 pixels gets more noise at each of 6 steps. Each step keeps a little less of the photo and mixes in fresh random noise.
# A simplified forward pass: 8 brightness values (a made-up photo strip) get more noise each step.
import math
import random
random.seed(7)
photo = [0.9, 0.9, 0.1, 0.1, 0.9, 0.1, 0.9, 0.9] # brightness, 0 (black) to 1 (white)
noise_per_step = [0.05, 0.10, 0.20, 0.35, 0.50, 0.70] # a made-up schedule: more noise each step
x = photo[:]
kept = 1.0 # how much of the original photo is still in the picture
for step, beta in enumerate(noise_per_step, start=1):
kept *= math.sqrt(1 - beta)
x = [math.sqrt(1 - beta) * v + math.sqrt(beta) * random.gauss(0, 1) for v in x]
print(f"step {step}: photo kept {kept:.2f}, first pixels {[round(v, 2) for v in x[:4]]}")
print(f"original first pixels: {photo[:4]}")Output
step 1: photo kept 0.97, first pixels [0.82, 0.99, 0.05, 0.03] step 2: photo kept 0.92, first pixels [1.11, 1.02, 0.17, 0.08] step 3: photo kept 0.83, first pixels [0.23, 0.13, -0.25, -0.13] step 4: photo kept 0.67, first pixels [0.37, 0.34, -0.59, 0.91] step 5: photo kept 0.47, first pixels [0.02, 0.16, 0.03, 0.82] step 6: photo kept 0.26, first pixels [-0.67, 0.3, 0.37, -0.8] original first pixels: [0.9, 0.9, 0.1, 0.1]
The share of the photo that is left falls from 0.97 after step 1 to 0.26 after step 6. By then the first pixels no longer look like the bright, bright, dark, dark pattern they started as. A real model uses about 1,000 much smaller steps, and the network learns to guess the noise added at each one.
“which is a Markov chain that gradually adds noise to the data in the opposite direction of sampling until signal is destroyed”
Ho and colleagues, 2020
“Creating noise from data is easy; creating data from noise is generative modeling.”
Song and colleagues, 2020
A Markov chain is a chain of steps where each step depends only on the one before it. That is what makes each noising step simple to define. The 2020 paper set the number of steps, T, to 1,000 in its experiments.
How does it make a new picture?
Making a picture starts where the damage ends: from random static. The network removes a little noise, then runs again on its own output, and again. After the last run, the result is the picture. Running these clean-up steps from random static to a finished picture is called sampling. The prompt is turned into numbers, and cross-attention layers (parts of the network that let the picture check those numbers) feed them in at every step, so each clean-up pass is pulled toward the words.
How a new picture is made
Random static
where every new picture starts
Text prompt
turned into numbers the model reads
Neural network
removes a little noise each run
Clean picture
left after the last clean-up run
- 1Each new picture starts as random static, not as a photo.
- 2The words are fed in, so every clean-up run is steered toward them.
- 3After many runs in a row, what is left is the picture.
A worked example with made-up numbers. A catalogue team needs 50,000 product shots a month. If each shot takes 1,000 clean-up runs, that is 50 million network runs a month. The latent diffusion paper says the same model architecture must run sequentially for a large number of steps, so one picture needs its steps one after another.
The hard part
Cost and waiting time per picture, multiplied by every picture the team makes.
The fix
Fewer steps cut the network runs each picture needs. A smaller space makes each run cheaper.
The check
Measure speed and quality on real shots before you promise the team a number.
How does latent diffusion work?
Running every step on full-size pixels is heavy. Latent diffusion first squeezes the picture into a smaller code, using an autoencoder (a model that squeezes an image down and can rebuild it). The clean-up runs on that small code, and the result is rebuilt into a full picture.
Pixel space or latent space
Pixel space (heavy)
Clean-up on every pixel
each run touches the whole picture
Latent space (cheaper)
Clean-up on a small code
fewer numbers, so each run is cheaper
Heavy to train and run
often hundreds of GPU days to train
Far less work per picture
the small code is rebuilt into a picture
- 1Pixel space runs every step on the full picture, which is heavy.
- 2Latent space runs the same steps on a small code, then rebuilds the picture.
“However, since these models typically operate directly in pixel space, optimization of powerful DMs often consumes hundreds of GPU days and inference is expensive due to sequential evaluations.”
Rombach and colleagues, 2022
“By introducing cross-attention layers into the model architecture, we turn diffusion models into powerful and flexible generators for general conditioning inputs such as text or bounding boxes”
Rombach and colleagues, 2022
The paper's main claim is about cost. A GPU day is a day of work on one graphics chip, so hundreds of them is a very large bill. The paper sets out to train on limited computing resources while keeping quality, and working in the smaller space cuts the work a lot compared with pixel models.
Are diffusion models better than GANs?
A GAN (generative adversarial network) trains two networks at once. One makes images and the other judges them, and they push each other. In 2021, Dhariwal and Nichol reported that diffusion models could reach image sample quality superior to the state-of-the-art generative models of the time. Their results were measured on ImageNet with FID, a score where lower is better.
- GAN
One maker, one judge
Two networks train against each other. The maker is the part that makes the picture.
- Diffusion
Many small steps
Very strong image quality, but each picture needs many network runs, one after another, which costs time and machine power.
So the honest answer is a trade-off. Diffusion gives strong quality, and you pay for it in time and machine power for every image.
How would you run it for 50,000 product photos a month?
Pick the smaller space
A latent model cuts the cost of each run, so the monthly bill drops.
Cut the steps
Use the fewest steps that still look right on your real product shots.
Budget it first
50,000 pictures times the cost of one picture is the number finance will ask for.
Keep a person in the loop
A reviewer checks labels and product shape before anything goes live.
What does the interviewer want to hear?
A strong answer covers
- A plain definition: a network that learns to remove noise, then makes pictures by cleaning up static.
- Training: noise is added to real photos, and the network learns to guess the noise.
- Generation: start from static, run many steps, guided by the prompt.
- The cost: many network runs per image, and how latent space helps.
- The trade-off: image quality against speed, compared with GANs.
- A real example of where the cost bites at scale.
Common traps
Trap"The model draws the picture step by step, like a painter."
BetterIt removes noise from static, guided by the prompt. It learned that by undoing damage in training.
Trap"Each new picture is a fresh training run."
BetterTraining happens once. Making a picture only runs the clean-up steps.
Trap"More steps always gives a better picture."
BetterEach step costs a full network run. Pick the fewest steps that keep quality on your real shots.
Can you spot the wrong note?
Spot the wrong note
A product team wrote four notes about their image tool. Which note is wrong?
Quick check
A team wants 50,000 images a month, each built from 1,000 steps. Which change cuts the cost most safely?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Learn it in depth
Last updated on 27 November 2026
Building an image feature for your product?
Venkat designs and builds AI products and agents, the UI and the system behind it. Book a short call and say what you need.