How AI Image Generation Works: A Beginner’s Playbook on Diffusion Models
Learn how AI image generation works in plain words: how diffusion models turn noise into pictures, how to write image prompts, edit safely and test results.
Meera is a developer in Pune. Her cousin Kabir runs a small bakery, and on Friday evening he sent her a message: “Can your AI make me a banner for the Diwali sweets box? By Monday?” Meera had used chatbots for code, but never for pictures. She typed “bakery banner” into an image tool and got a cake with seven candles, melted letters and a hand with six fingers.
So she stopped and asked a better question: how AI image generation works under the hood. Once she understood that, the fixes became obvious. This playbook walks you through what she learned, in plain words, so you can get from “random weird picture” to “picture I can actually use”.
Last verified: 1 December 2026. AI tools change fast; check the linked sources for anything newer.
Who this is for: complete beginners, designers and developers who want to use text-to-image tools well. No maths needed. Time needed: about 30-45 minutes, plus some fun experimenting.
How AI image generation works, in simple words
Most image tools today use a diffusion model. A diffusion model is a program that has learned to turn random noise into a picture, one small clean-up step at a time.
Think of a foggy bathroom mirror. Training is like watching thousands of clear photos slowly fog up, step by step, until they are pure grey static. The model practises the reverse: given a foggy picture, guess what fog to wipe away. After enough practice, you can hand it pure fog and it wipes, and wipes, until a picture appears.
The precise version: during training, noise is added to images in many small steps, and a neural network learns to predict that noise so it can be removed. At generation time, it starts from random noise and removes predicted noise over many steps.
Where your prompt fits in
Wiping fog at random would give a random picture. Your words steer it. A text encoder turns your prompt into numbers (an embedding), and at every step the model looks at those numbers while deciding what to wipe. In Stable Diffusion, that text encoder is CLIP and the part doing the wiping is called a U-Net.
Why it is fast enough to run
Cleaning a full-size photo pixel by pixel is slow. So tools like Stable Diffusion work on a small, squeezed sketch of the image, called a latent. Hugging Face explains that its autoencoder shrinks a 512 x 512 image into a 64 x 64 latent (a reduction factor of 8). A decoder then blows the finished sketch back up into a real picture.
The four dials you will see
- Steps: how many wiping rounds. Hugging Face’s Stable Diffusion guide uses 50 by default and notes that far fewer steps (such as 15) noticeably hurt quality.
- Guidance scale: how strictly to follow your words. Higher means closer to the prompt but less variety. The same guide suggests 7 to 8.5 for Stable Diffusion, with 7.5 as the default.
- Seed: the starting noise. Same seed, same settings, same prompt gives the same picture again.
- Negative prompt: things to steer away from, such as “blurry, text, extra fingers”.
Hosted apps may hide some of these dials, but the ideas are the same everywhere.
The playbook at a glance
- Write a short brief before you write a prompt.
- Build the prompt in layers: subject, scene, style, framing.
- Use the dials on purpose and save the seed.
- Fix parts of the picture with inpainting, not full rerolls.
- Check licences, people and labels before you publish.
- Test pictures against your brief, not your mood.
Play 1: Write a short brief first
Goal: know what “good” looks like before the model guesses for you.
- Write where the image will be used (web banner, phone story, print).
- Write the size and shape (wide, square, tall).
- List three must-haves and one must-not.
Meera wrote: “Wide website banner. Must have: a box of Indian sweets, warm diya light, empty space on the left for text. Must not: any written words in the image.”
You are done when: someone else could read your brief and say whether a picture passes.
Play 2: Build the image prompt in layers
Goal: give the model clear words to steer by. Image prompts work differently from chat prompts: describe what the picture looks like, not what you want done.
- Subject: the main thing. “An open box of Indian sweets: laddoos and kaju katli.”
- Scene: where and when. “On a wooden table, small diyas glowing at night.”
- Style: the look. “Warm food photography, soft focus background.”
- Framing: camera and layout. “Wide shot, sweets on the right, empty dark space on the left.”
Change one layer at a time, so you learn which words matter. Keep a negative prompt for the things you keep seeing and do not want.
Meera’s first layered prompt already gave her the right box and light. Only the framing was off.
You are done when: at least one in four images is close to your brief.
Play 3: Use the dials on purpose and save the seed
Goal: stop rolling dice. Once you like a picture, lock its seed so you can make small changes without losing it.
- Generate 4 images with default settings and pick the best.
- Note its seed. Keep it fixed from now on.
- If it ignores your words, raise guidance a little. If it looks harsh or over-cooked, lower it.
- Do not drop the steps very low to save time unless you have tested the quality.
If you code, this is what those dials look like with the open-source Hugging Face Diffusers library. It is an illustration; hosted APIs name things differently.
import torch
from diffusers import AutoPipelineForText2Image
pipe = AutoPipelineForText2Image.from_pretrained(
"stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16).to("cuda")
seed = torch.Generator("cuda").manual_seed(42) # same seed = same picture
image = pipe("open box of Indian sweets, diyas, warm food photo, wide shot",
negative_prompt="text, letters, blurry",
num_inference_steps=50, guidance_scale=7.5, generator=seed).images[0]
image.save("banner.png")In plain steps: load a model, fix the starting noise with a seed, describe the picture and what to avoid, run 50 clean-up steps with medium strictness, and save the result.
You are done when: you can recreate your favourite image on demand.
Play 4: Fix parts with inpainting, not full rerolls
Goal: repair one bad spot without throwing away a good picture.
Inpainting means redrawing only part of an image. You paint a mask over the spot: in the Diffusers docs, white areas get redrawn and black areas are kept. It is like putting tape around one tile before you repaint it.
- Mask only the broken part, with a little margin.
- Write a prompt for what should be there (“a plain brass diya”).
- Soften the mask edges (blur) if the patch shows a hard seam.
- Use strength to choose how much changes: higher means a bigger change, lower stays closer to the original.
Meera’s best banner had one diya melting into the table. She masked it, asked for “a plain brass diya with a small flame”, and kept everything else.
You are done when: the fix blends in and the rest of the image did not move.
Play 5: Check licences, people and labels
Goal: publish images you are allowed to use and that do not mislead anyone.
- Read the terms of your tool or model. Open models come with licences too; Stable Diffusion weights, for example, use the CreativeML OpenRAIL-M licence with use restrictions.
- Do not create realistic images of real people, logos or brands you do not own.
- Do not present an AI picture as a real photo of a real product or event.
- Keep provenance labels when your tool adds them. C2PA Content Credentials are an open standard that records where content came from and how it was edited, “like a nutrition label”.
Meera added a small “illustration” note under the banner, because the sweets in it were not Kabir’s real sweets.
You are done when: you can explain where the image came from and why you may use it.
Play 6: Test pictures against your brief
Goal: choose with a checklist, not with tired eyes at midnight. This is the same idea as AI evals, just for pictures.
- Turn your brief into yes/no checks: right subject, right shape, space for text, no stray letters.
- Zoom to 100% and look at hands, faces, edges and any text.
- Place the image in the real layout (with the heading on top) before deciding.
- Show two finalists to one other person and ask “which fits the brief?”.
You are done when: one image passes every check in the real layout.
Do you need this? Picking a way to generate images
| Option | Good for | Trade-off |
|---|---|---|
| Chat or design app with images built in | One-off pictures, no setup | Fewer dials, follow the app’s rules |
| Hosted image API | Adding images to your own app | Pay per image, data leaves your machine |
| Open model on your own GPU | Full control, privacy, many images | Needs a capable GPU and setup time |
Running open models locally follows the same ideas as our local LLM playbook.
Mistakes to avoid
- Asking for words inside the image. Many models still garble text. Fix: leave empty space and add the text in a design tool.
- Rerolling forever. Fix: save the seed of a good image and change one thing at a time.
- Cranking guidance to the maximum. Fix: stay near the tool’s default and nudge it.
- Prompt soup. Thirty style words fight each other. Fix: one clear style, one clear subject.
- Skipping the licence. Fix: read it before the image goes on a product or ad.
How to know it is working
- You need fewer than 10 tries to reach a usable image.
- You can recreate any final image from its saved prompt, settings and seed.
- Small fixes happen with inpainting, not by starting over.
- Every published image passes your brief checklist.
Your checklist
- ☐ Brief written: use, shape, three must-haves, one must-not
- ☐ Prompt built in layers: subject, scene, style, framing
- ☐ Negative prompt for repeat problems
- ☐ Seed and settings saved for the chosen image
- ☐ Broken spots fixed with inpainting
- ☐ Licence read, no real people or brands, labelled if needed
- ☐ Checked at 100% zoom and in the real layout
Frequently asked questions
Does AI image generation copy existing pictures?
A diffusion model does not paste stored photos together; it builds a new image from noise using patterns learned in training. Still, it can produce things close to famous works or styles, so avoid prompts naming living artists or brands, and check your tool’s terms.
Why do AI images get hands and text wrong?
Hands and letters have many small parts that must be exactly right, and tiny mistakes are easy for us to spot. Newer models do better, but zoom in and check. Inpainting is the quickest fix for a bad hand.
Why do I get a different picture every time?
Each run starts from different random noise. Fix the seed and keep the other settings the same, and you get the same picture again.
Do I need a powerful computer?
Not to start. Hosted apps and APIs run on their own servers. To run open models yourself you need a decent GPU, and tricks like quantization help on smaller machines.
Can I teach a model my own style or product?
Yes. Small add-on adapters, trained with methods like LoRA, can teach an open image model a style or object from a modest set of your own images.
Back to Meera’s Monday deadline
On Sunday night Meera sent Kabir one banner: a glowing box of laddoos on the right, soft diya light, clean space on the left where she typed “Diwali Sweets Box” in the bakery’s own font. It took her 12 tries instead of an endless evening (an illustrative number, but the feeling is real).
Now that you know how AI image generation works, try it yourself: write a four-line brief, build one layered prompt and save the seed of your favourite result. Next on the CodeSpy roadmap: agents that can see a screen and click for you.
Sources: Hugging Face: Stable Diffusion with Diffusers (latent diffusion, steps, guidance, seeds, licence); Hugging Face Diffusers: Inpainting (masks, strength, negative prompts, mask blur); C2PA (Content Credentials).


