Back to Blog
EducationAugust 17, 2026·13 min read

How AI Generates Images: Diffusion Models Explained

By Harmandeep Mand, founder of Airbin

Table of Contents

  • A Brief History: How We Got Here
  • Early Approaches: VAEs and GANs
  • The Diffusion Revolution
  • The Core Idea: Destroying and Recreating
  • The Forward Process (Adding Noise)
  • The Reverse Process (Removing Noise)
  • The Technical Mechanics
  • Noise Scheduling
  • The U-Net: The Workhorse Architecture
  • Sampling: Generating an Image
  • Adding Text Control: How Prompts Become Images
  • CLIP: Bridging Text and Images
  • Cross-Attention: Where Text Meets Image
  • Classifier-Free Guidance
  • Latent Diffusion: The Efficiency Breakthrough
  • How It Works
  • What Is Latent Space?
  • The Major Systems
  • Recent Advances
  • Flow Matching and Rectified Flows
  • DiT: Diffusion Transformers
  • Consistency Models
  • Video and 3D
  • Limitations and Open Challenges
  • Why Understanding This Matters
  • Further Reading

How AI Generates Images: Diffusion Models Explained

You type a few words into a text box. Seconds later, a fully formed image appears: a watercolor painting of a cat reading a book in a library, or a photorealistic sunset over a city that does not exist. It feels like magic, but the technology behind it is grounded in decades of research in probability, statistics, and neural networks.

This article explains how diffusion models, the architecture powering most modern AI image generators, actually work. We will trace the history from earlier approaches, break down the core mechanics, and explain the key concepts that make text-to-image generation possible.

A Brief History: How We Got Here

Early Approaches: VAEs and GANs

Before diffusion models took over, two architectures dominated generative AI for images.

Variational Autoencoders (VAEs), introduced around 2013, learn to compress images into a compact representation (a latent space) and then reconstruct them. They are stable to train but tend to produce blurry outputs because they optimize for average pixel values rather than sharp details.

Generative Adversarial Networks (GANs), introduced by Ian Goodfellow in 2014, use a two-network setup: a generator creates fake images, and a discriminator tries to distinguish fakes from real images. They compete in a minimax game, and over time, the generator learns to produce increasingly convincing images.

GANs could produce strikingly sharp images, but they had serious drawbacks:

  • Mode collapse: The generator learns to produce only a few types of outputs, ignoring the diversity of the training data.
  • Training instability: The adversarial game is hard to balance. Training frequently diverges or oscillates.
  • Limited controllability: Steering a GAN to produce a specific scene from a text description required complex additional architectures.

Notable GAN-based systems included StyleGAN (famous for generating photorealistic faces) and BigGAN (which produced high-resolution images from class labels). But GANs struggled with complex scenes, compositional understanding, and textual control.

The Diffusion Revolution

In 2020, a paper by Ho, Jain, and Abbeel titled "Denoising Diffusion Probabilistic Models" (DDPM) demonstrated that a different approach, inspired by non-equilibrium thermodynamics, could generate high-quality images without the adversarial training instability of GANs. By 2022, diffusion models had overtaken GANs as the dominant architecture for image generation.

The Core Idea: Destroying and Recreating

The fundamental insight behind diffusion models is surprisingly elegant:

It is easier to learn how to remove noise from an image than to learn how to generate an image from scratch.

The process has two phases:

The Forward Process (Adding Noise)

Take a real image and gradually add random Gaussian noise to it over many steps. After enough steps, the image becomes pure static, indistinguishable from random noise. This is a simple, deterministic process. No learning is required.

Think of it like this: imagine taking a photograph and slowly scattering sand across it, grain by grain, until the original image is completely buried and all you see is a flat layer of sand.

The Reverse Process (Removing Noise)

Train a neural network to reverse this process: given a noisy image at any step, predict and remove the noise to recover a slightly less noisy version. Stack these denoising steps together, starting from pure noise, and the network gradually "sculpts" a coherent image out of randomness.

To extend the analogy: the neural network learns how to carefully brush away sand, one layer at a time, to reveal a picture beneath. The remarkable part is that it can reveal pictures it has never seen before, because it has learned the general statistical structure of what images look like.

The Technical Mechanics

Noise Scheduling

The forward process does not add noise uniformly. A noise schedule defines how much noise is added at each timestep. The schedule is typically designed so that:

  • Early steps add small amounts of noise (the image is still mostly recognizable).
  • Later steps add larger increments (the image quickly becomes unrecognizable).

Common schedules include linear, cosine, and sigmoid schedules. The cosine schedule, introduced by Nichol and Dhariwal, was found to produce better results because it preserves more image information in the early steps, giving the model a gentler task.

Mathematically, at each timestep t, the noisy image x_t is computed as:

x_t = sqrt(alpha_t) * x_0 + sqrt(1 - alpha_t) * epsilon

Where x_0 is the original image, epsilon is random Gaussian noise, and alpha_t is a value from the noise schedule that decreases over time.

The U-Net: The Workhorse Architecture

The neural network at the heart of most diffusion models is a U-Net, an architecture originally developed for medical image segmentation. It has an encoder-decoder structure with skip connections:

  1. Encoder path: Progressively downsamples the image, capturing high-level features at lower resolutions.
  2. Bottleneck: Processes the most compressed representation.
  3. Decoder path: Progressively upsamples back to the original resolution.
  4. Skip connections: Pass detailed spatial information from the encoder directly to corresponding decoder layers, preserving fine details.

The U-Net takes two inputs:

  • The noisy image at timestep t
  • The timestep t itself (embedded as a vector so the network knows how much noise to expect)

It outputs a prediction of the noise that was added, which is then subtracted from the noisy image to produce a cleaner version.

Sampling: Generating an Image

To generate a new image:

  1. Start with a tensor of pure random Gaussian noise.
  2. Feed it to the U-Net along with the final timestep indicator.
  3. The U-Net predicts the noise component.
  4. Subtract the predicted noise (scaled appropriately) to get a slightly less noisy image.
  5. Repeat for each timestep, stepping backward through the noise schedule.
  6. After all steps, the result is a clean, generated image.

Early diffusion models required hundreds or thousands of steps for good results. Subsequent work on improved samplers (DDIM, DPM-Solver, and others) reduced this to 20-50 steps without significant quality loss, and some methods can produce reasonable outputs in as few as 4-8 steps.

Adding Text Control: How Prompts Become Images

The raw diffusion model described above generates random images from the learned distribution. To control what the image depicts, we need to condition the model on text input. This is where things get especially interesting.

CLIP: Bridging Text and Images

CLIP (Contrastive Language-Image Pre-training), developed by OpenAI, is a model trained on hundreds of millions of image-text pairs scraped from the internet. It learns a shared embedding space where text descriptions and their corresponding images are close together.

CLIP consists of two encoders:

  • A text encoder that converts text into a vector (embedding).
  • An image encoder that converts images into vectors in the same space.

During training, CLIP learns to maximize the similarity between matching image-text pairs and minimize the similarity between non-matching pairs. The result is a text encoder that produces rich semantic representations of natural language descriptions.

In text-to-image diffusion models, the text encoder (or a similar model like T5) converts your prompt into a sequence of embedding vectors. These vectors are then injected into the U-Net through cross-attention layers, which allow the denoising process at each spatial location to attend to relevant parts of the text description.

Cross-Attention: Where Text Meets Image

Cross-attention is the mechanism that allows the U-Net to "read" the text prompt while denoising. At multiple layers within the U-Net:

  1. The image features at that layer serve as the query.
  2. The text embeddings serve as the key and value.
  3. The attention mechanism computes which parts of the text are most relevant to each spatial region of the image.

For example, when denoising the upper-left region of an image prompted with "a red barn under a blue sky," the cross-attention mechanism might attend strongly to "blue sky" for upper regions and "red barn" for lower regions.

Classifier-Free Guidance

Even with text conditioning, early models sometimes produced images that only loosely matched the prompt. Classifier-free guidance (CFG), introduced by Ho and Salimans, dramatically improved prompt adherence.

The idea is elegantly simple. During training, the model occasionally drops the text conditioning (replacing it with an empty or null prompt) so it learns to generate both conditionally and unconditionally. During generation, the model computes two predictions at each step:

  • Conditional prediction: What the model would generate given the text prompt.
  • Unconditional prediction: What the model would generate with no prompt.

The final prediction is computed as:

output = unconditional + guidance_scale * (conditional - unconditional)

The guidance scale (typically between 5 and 15) controls how strongly the model follows the prompt. Higher values produce images that more closely match the text but may sacrifice diversity and naturalness. Lower values produce more varied but less prompt-faithful results.

This is why most AI image tools expose a "guidance scale" or "prompt strength" setting. It directly controls this mathematical trade-off.

Latent Diffusion: The Efficiency Breakthrough

Running the diffusion process directly on full-resolution images (say, 512x512 pixels with 3 color channels) is computationally brutal. Each denoising step requires a full forward pass through a large U-Net, and you need dozens of steps.

Latent Diffusion Models (LDMs), introduced by Rombach et al. in 2022, solved this by moving the diffusion process into a compressed latent space.

How It Works

  1. A VAE encoder compresses the image from pixel space (e.g., 512x512x3) into a much smaller latent representation (e.g., 64x64x4). This is a roughly 48x compression.
  2. The diffusion process (noise addition and denoising) happens entirely in this compact latent space.
  3. A VAE decoder converts the final denoised latent representation back to pixel space.

This is the architecture behind Stable Diffusion, and it reduced the computational requirements by roughly an order of magnitude compared to pixel-space diffusion, making it feasible to run on consumer GPUs.

What Is Latent Space?

Latent space is an abstract, compressed representation of images learned by the VAE. Each point in latent space corresponds to a possible image. Nearby points correspond to similar images. The VAE learns to map images into this space and back out again, discarding perceptually irrelevant information (like exact pixel noise patterns) while preserving meaningful structure (shapes, colors, textures, objects).

Think of latent space as a very efficient filing system. Instead of storing every pixel of every possible image, it stores a compact code that captures the "essence" of an image. The diffusion model then operates on these compact codes rather than raw pixels.

The Major Systems

Several systems have implemented and extended these ideas:

SystemDeveloperKey Characteristics
DALL-E 2OpenAIUses CLIP embeddings and a diffusion prior; generates via a diffusion decoder
DALL-E 3OpenAIImproved prompt understanding through training on detailed captions
Stable DiffusionStability AIOpen-source latent diffusion model; runs on consumer hardware
MidjourneyMidjourney Inc.Proprietary model known for distinctive artistic aesthetics
ImagenGoogle DeepMindUses a large T5 language model for text encoding instead of CLIP
Imagen 3Google DeepMindSuccessor with improved photorealism and prompt adherence

Each system makes different architectural choices (which text encoder, what resolution, how many diffusion steps, what training data), but they all share the fundamental diffusion framework described above.

Recent Advances

Flow Matching and Rectified Flows

Newer approaches, including flow matching, reformulate the generation process as learning a smooth transport path from noise to data, rather than a discrete chain of denoising steps. This can produce higher-quality results with fewer steps.

DiT: Diffusion Transformers

The U-Net is being supplemented or replaced by transformer architectures in some newer models. Diffusion Transformers (DiT) replace the convolutional U-Net with a vision transformer, and have shown improved scaling behavior: they get better more predictably as you increase model size and training compute.

Consistency Models

Developed at OpenAI, consistency models aim to distill the multi-step diffusion process into a single step or very few steps, enabling near-instant image generation while maintaining quality close to full multi-step diffusion.

Video and 3D

The same diffusion framework is being extended to video generation (by treating video as a sequence of frames with temporal attention) and 3D asset generation. Systems like Sora, Runway Gen-3, and Kling apply diffusion principles to generate video content.

Limitations and Open Challenges

Despite their impressive capabilities, diffusion models have known limitations:

  • Compositionality: Generating images with specific spatial relationships ("a red cube on top of a blue sphere to the left of a green cylinder") remains challenging. Models often struggle with precise counting, spatial reasoning, and attribute binding.
  • Text rendering: Generating readable text within images has been a persistent weakness, though recent models have shown improvement.
  • Anatomical accuracy: Human hands, teeth, and complex body poses continue to produce artifacts, though this is improving with each generation.
  • Bias: Models reflect biases present in their training data, including demographic biases, cultural biases, and aesthetic preferences of the internet-scraped data they learn from.
  • Computational cost: Training these models requires enormous compute resources and large datasets, raising questions about environmental impact and accessibility.

Why Understanding This Matters

Knowing how diffusion models work is not just academic curiosity. It has practical implications:

  • Better prompting: Understanding that CLIP text encoding is what translates your words into the model's "understanding" helps explain why certain prompt structures work better than others.
  • Informed criticism: As AI-generated images become more prevalent, understanding the technology helps evaluate claims about AI capabilities and limitations.
  • Ethical reasoning: Debates about AI-generated art, copyright, and deepfakes benefit from understanding what these models actually learn and how they generate outputs.
  • Career relevance: Whether you work in design, media, research, or software, fluency with generative AI concepts is increasingly valuable.

Further Reading

For those who want to go deeper, these foundational papers are worth reading:

  • Ho, Jain, Abbeel. "Denoising Diffusion Probabilistic Models" (2020)
  • Rombach et al. "High-Resolution Image Synthesis with Latent Diffusion Models" (2022)
  • Radford et al. "Learning Transferable Visual Models From Natural Language Supervision" (CLIP, 2021)
  • Ho and Salimans. "Classifier-Free Diffusion Guidance" (2022)
  • Peebles and Xie. "Scalable Diffusion Models with Transformers" (DiT, 2023)

The field moves fast, but the fundamentals described in this article, noise, denoising, latent spaces, text conditioning, and guided sampling, remain the foundation on which current and near-future systems are built.

AIMachine LearningDiffusion ModelsEducationComputer Vision
HM

Harmandeep Mand

Founder of Airbin

Harmandeep founded Airbin and builds it: the web app, the phone apps and the servers behind them. He writes these guides and corrects them when the product or the facts change. Spotted a mistake? Email support@airbin.app.

Follow Airbin for new guides

Short videos, tips and new guides. Follow or subscribe so you don't miss the next one.

  • YouTube
  • Instagram
  • LinkedIn

Related Articles

Education

How Large Language Models Work: A Non-Technical Guide to the AI Behind ChatGPT, Claude, and Gemini

Aug 25, 2026·13 min read
Education

The Science Behind AI Music Generation: How Neural Networks Compose

Aug 17, 2026·13 min read
Education

How AI Translation Models Handle Technical and Academic Vocabulary

Aug 17, 2026·13 min read

Ready to try Airbin?

Your AI assistant that remembers you. Find places, edit files, create anything. Get started for free.

Get Started

Ready to Get Started?

Start with a free account and upgrade only if you need more.

Airbin logoAirbin

Your AI assistant that remembers you. Find places, edit files, create anything.

Product

  • Pricing
  • Download App
  • Blog
  • Stories
  • Compare
  • Tools

Company

  • About Us
  • Contact Us
  • FAQ
  • Solutions

Legal

  • Legal
  • Privacy
  • Cookie Policy
  • Terms
  • Do Not Sell My Info
© 2026 Airbin. All rights reserved.