How image generation works

A companion to How AI Predicts the Next Word

How Image Generation Works

An AI-generated picture of an alligator on the left and a crocodile on the right, facing each other across a muddy creek lined with mangroves
Generated by Nano Banana, Google DeepMind's image model, officially Gemini 2.5 Flash Image, released 26 August 2025. Nobody took this photograph. There is no creek, no mangroves, and no animals.
Hold this question Alligator on the left; broad rounded snout, dark hide, teeth tucked away. Crocodile on the right; narrower tapering snout, lighter olive hide, teeth showing along the closed jaw. Those are the real tells, and the machine got them right. How does a machine that has never been near a billabong know the difference?

We will answer it properly at the end. Click anywhere, tap, or use the arrow keys to move through.

Start small: a cell that goes ping

A brain cell, or the artificial kind in this machine, mostly just sits there. Sometimes it goes ping. It decides to ping based on how many pings are arriving from the cells connected to it, and how strong each connection is. That is the whole component. Everything else is just lots of them.

A B C quiet

Click the small cells to make them ping. The thick wire counts double, because that connection is strong.

arriving: 0 · needs 3 to fire

A cell never sees the whole picture. It only ever asks one tiny question: are my neighbours pinging hard enough?

Stack them up: edges, then beak, then bird

How do you recognise a bird? You do not write rules for "bird". You build upward, layer by layer, each layer pinging when the layer below gives it something to ping about.

Bottom layer: pixels
A pixel is one tiny dot of the picture. Some bright, some dark. That is all this layer knows.
Next: edge detectors
A cell here pings when bright pixels sit beside dark ones. Bright against dark is an edge.
Next: little parts
Cells that ping when a few edges line up: a pointy thing that might be a beak, a small circle that might be an eye.
Next: a possible head
One cell pings only when a possible beak and a possible eye sit in the right place together.
Top: bird
Head plus wing plus feet, all pinging at once. A cell up here says: probably a bird.

Nobody sets those connections by hand

The connection strengths start out random. You show the machine a labelled picture and ask: bird or not? Then you nudge every connection a tiny bit in whichever direction makes the guess less wrong, and you do that across millions of labelled pictures, millions of times. That nudging is the learning. That is all "training" is.

LABEL: BIRD

The machine's guess: 50% bird, which is a coin flip. It has no idea.

labelled pictures seen: 0 · connections: random

No rules were typed in. The idea of "beak" was never programmed. It grew, because having a beak detector made the guesses less wrong.

This is not a mystery ingredient

A labelled dataset is just pictures with a word attached to each one. You can browse them. Here is a real one, open in the TensorFlow Datasets catalogue: a file path, a thumbnail, and a label that says 0 (cat) or 1 (dog). That is the whole format. About 23,000 photos in this one.

Screenshot of the TensorFlow Datasets catalogue page for cats_vs_dogs, showing a table with columns for image, filename and label; rows show dog and cat photographs labelled 1 (dog) or 0 (cat)
Screenshot: the cats_vs_dogs dataset in the TensorFlow Datasets catalogue, 23,262 photographs, accessed 14 August 2026. Browse it yourself at tensorflow.org/datasets/catalog/cats_vs_dogs.
Every "magical" thing later in this page is built on a table that looks like the one above. Pictures, and a word for each.

The label does not have to be "car"

Cat or dog is a coarse difference. But there is nothing special about coarse. Here is cars196, another catalogue dataset: 16,185 photographs sorted into 196 classes, and the class is the make, the model and the year.

Screenshot of the TensorFlow Datasets catalogue page for cars196, showing sample photographs labelled with specific makes, models and years such as Volvo XC90 SUV 2007 and Hyundai Santa Fe SUV 2012
Screenshot: the cars196 dataset in the TensorFlow Datasets catalogue, 16,185 images across 196 classes, accessed 14 August 2026. Labels read "Volvo XC90 SUV 2007", "Hyundai Santa Fe SUV 2012", "Bentley Arnage Sedan 2009". Original dataset: Krause, Stark, Deng and Fei-Fei, Stanford, 2013. Catalogue page: tensorflow.org/datasets/catalog/cars196.
Nobody wrote a rule for what makes a 2007 Volvo XC90 different from a 2012 Hyundai Santa Fe. The machine found the differences itself, because finding them made its guesses less wrong. Fine differences are learnt exactly the same way as coarse ones. Hold on to that; it is half the answer to our opening question.

So: crocodile or alligator

Here in the Territory we know the difference at a glance. Give a machine enough labelled photographs and it would find the same tells, without anyone typing a rule. Click each feature.

Crocodile
Alligator

Three tells, all learnable from examples.

Look back at the opening picture and you will see all three tells rendered correctly. But knowing the difference is only half of it. Something still has to connect the word you typed to the picture that comes out. That is next.

Words and pictures, filed in the same place

In February 2021 a team at OpenAI trained two models at once: one that reads text, one that looks at pictures. Both produce a list of 512 numbers, which you can think of as an address. They were trained on 400 million picture-and-caption pairs so that a picture and its own caption land at nearly the same address, and mismatched pairs land far apart. The model is called CLIP.

photo: croc on a bank photo: gator in a swamp photo: white Hilux photo: mangrove creek photo: goanna on sand

The real space has 512 dimensions. This is a flat sketch of it, so you can see the idea: nearness means "these mean the same sort of thing".

Pick a word. It gets an address in the same space the pictures live in, and the nearest picture lights up.

The addresses behave like arithmetic on ideas. In the video linked at the end, the presenter takes a photo of himself in a hat, subtracts a photo of himself without one, and searches for the word closest to what is left over.

with hat
without hat
=
the word "hat"then cap, then helmet
The machine is not storing pictures of hats. It has learnt a space in which the idea of a hat is a direction you can travel in. Type "crocodile" and you get an address; type "alligator" and you get a different one, close by but genuinely distinct, because in 400 million captions people used those two words about different animals.

Source: Radford et al., "Learning Transferable Visual Models From Natural Language Supervision", OpenAI, 26 February 2021, arxiv.org/abs/2103.00020. The hat demonstration is from the Welch Labs video linked at the end, at 6:24.

Now run the whole thing in reverse

CLIP only goes one way; it turns pictures and words into addresses, and cannot turn an address back into a picture. Something else does that. Start with a square of pure random static, like an old TV between channels. Then ask, over and over: if this static were slowly becoming "a crocodile driving a Hilux", which speckles should change, and which way?

Honest version of the fancy word: the machine is removing noise a little at a time until a picture that matches your words is left standing.
Two details that surprise people. It is not trained to tidy up one small step at a time; it is trained to predict all the noise at once, and then take a small step in that direction. And during generation it adds a little fresh randomness back in at each pass. Take that randomness out and the pictures come back blurry, because the machine settles on the average of everything it has seen, and averages look like mush.

Source: Ho, Jain and Abbeel, "Denoising Diffusion Probabilistic Models", UC Berkeley, 19 June 2020, arxiv.org/abs/2006.11239. The blurry-tree demonstration is in the Welch Labs video at 10:23.

Asking is not the same as getting

Handing the machine your words is called conditioning, and on its own it is disappointingly weak. Researchers asked a well known model for a tree in the desert and got a desert, and a shadow where a tree should be, and no tree. The fix is to compare two runs: one that was told your words, and one that was told nothing. The difference between them points towards what your words actually added, and you can turn that up.

guidance scale: 0 · conditioning only

This trick is called classifier-free guidance, and it is in nearly every image and video model you can use today. When you notice a picture obeying your prompt almost too literally, this is the dial responsible.

Illustration of a published result; the actual generated images are in the Welch Labs video at 33:08. Method: Ho and Salimans, "Classifier-Free Diffusion Guidance", arxiv.org/abs/2207.12598, NeurIPS workshop December 2021. The tree-in-the-desert runs used Stable Diffusion; Rombach et al., "High-Resolution Image Synthesis with Latent Diffusion Models", Heidelberg, 20 December 2021, arxiv.org/abs/2112.10752.

Why everyone's crocodile is different

The static it starts from is fresh and random every single time. Different static means the nudges land differently, so the same words end somewhere new. Same prompt, three runs:

Generative AI is not looking anything up. It is imagining, from noise, guided by your words. That is why no two are alike.

Back to the two animals

The same AI-generated picture of an alligator and a crocodile facing each other across a muddy creek
The picture we started with. Still nobody's photograph.

Nothing mystical happened. Four ordinary things stacked up.

One

Millions of captioned photographs on the internet, in which people writing about crocodiles and people writing about alligators were describing different animals.

Two

A text model and a picture model trained together until those two words landed at different addresses, and each address sat near the pictures that matched it.

Three

A generator that starts from static and repeatedly asks which speckles to change, using those addresses as the instruction.

Four

Guidance, amplifying whatever the words added, which is why you got a broad snout on one side of the creek and a narrow one on the other rather than two generic lizards.

The honest caveat: the machine has learnt how the words are used, not what the animals are. It has no idea that a saltie can kill you. Where the captions were wrong, it will be confidently wrong too, and it will not tell you which parts those are. That is the whole reason a person still checks the output.

Now prove it with the room

Everyone, at the same time, give your AI tool the exact same prompt:

Show me a picture of a crocodile driving a Hilux.

Then compare screens. Thirty people, thirty different crocodiles. You now know exactly why: thirty squares of fresh static, each nudged until it matched the same nine words.

The one idea to keep

The machine learnt what things look like from millions of captioned pictures, feature by feature, and learnt to file words and pictures at the same addresses. To make a new picture it starts from random static and nudges it towards the address your words point to. Fresh static every time is why the same words never paint the same picture twice.

Where this connects

This page's sibling, How AI Predicts the Next Word, tells the same story for text: weighted dice instead of nudged static, and the same lesson at the end. The machine predicts; it does not look up.

Thirty-seven minutes, and worth every one

Everything on this page is the plain-language version of one exceptional explainer. If you want the mathematics underneath, with the animations that make it click, watch this.

Stephen Welch (Welch Labs), "But how do AI images and videos actually work?", guest video on 3Blue1Brown, 25 July 2025, 37:20. youtube.com/watch?v=iv-5mZ_9CPY. Chapters: CLIP at 3:37, shared embedding space at 6:25, diffusion and DDPM at 8:16, vector fields at 11:44, DDIM at 22:00, DALL·E 2 at 25:25, conditioning at 26:37, guidance at 30:02.

Sources used

  • Radford et al., "Learning Transferable Visual Models From Natural Language Supervision" (CLIP), OpenAI, 26 February 2021. arxiv.org/abs/2103.00020
  • Ho, Jain and Abbeel, "Denoising Diffusion Probabilistic Models" (DDPM), UC Berkeley, 19 June 2020. arxiv.org/abs/2006.11239
  • Song, Meng and Ermon, "Denoising Diffusion Implicit Models" (DDIM), Stanford, 6 October 2020. arxiv.org/abs/2010.02502
  • Ho and Salimans, "Classifier-Free Diffusion Guidance", NeurIPS workshop, December 2021. arxiv.org/abs/2207.12598
  • Ramesh et al., "Hierarchical Text-Conditional Image Generation with CLIP Latents" (unCLIP, released as DALL·E 2), OpenAI, 13 April 2022. arxiv.org/abs/2204.06125
  • Rombach et al., "High-Resolution Image Synthesis with Latent Diffusion Models" (Stable Diffusion), Heidelberg, 20 December 2021. arxiv.org/abs/2112.10752
  • TensorFlow Datasets catalogue, cats_vs_dogs and cars196, accessed 14 August 2026. cats_vs_dogs · cars196
  • Krause, Stark, Deng and Fei-Fei, "3D Object Representations for Fine-Grained Categorization" (the Stanford Cars dataset behind cars196), 2013. catalogue entry
  • Nano Banana, officially Gemini 2.5 Flash Image, Google DeepMind, released 26 August 2025. blog.google
  • Stephen Welch (Welch Labs), "But how do AI images and videos actually work?", 3Blue1Brown, 25 July 2025. 3blue1brown.com/lessons/diffusion-models

Opening and closing image generated with Nano Banana. The crocodile-driving-a-Hilux images were generated for this page. The two screenshots are of public documentation pages, reproduced for teaching.