How Stable Diffusion Works: A Visual Explanation
Jay Alammar breaks down the components and process behind the popular AI image generation model.

Takeaways
- ›Stable Diffusion uses a text encoder, image generator, and decoder to create images from text
- ›The 'diffusion' process gradually refines random noise into a coherent image
- ›Operating in latent space allows for faster processing than pixel-based models
- ›Despite impressive results, the technology faces technical limitations and ethical challenges
AI image generation has captured public imagination with its ability to create striking visuals from text descriptions. The release of Stable Diffusion marked a significant milestone, making a high-performance model widely accessible. But how does it actually work? Let's look under the hood.
The Components of Stable Diffusion
Stable Diffusion is not a single monolithic model, but a system of several interacting components:
-
Text Encoder: A specialized transformer language model (specifically, the text encoder from a CLIP model) that converts input text into numerical representations capturing the ideas in the prompt.
-
Image Generator: The core of the system, composed of two parts: , Image Information Creator: This is where much of Stable Diffusion's performance gains come from. It operates in the 'latent space' of image information rather than directly with pixels, making it faster than previous models. , Image Decoder: This component takes the processed information and produces the final pixel image.
-
UNet and Scheduler: These work together in the Image Information Creator to gradually process and 'diffuse' information over multiple steps.
The Diffusion Process
The term 'diffusion' describes the step-by-step processing that leads to a high-quality image. It starts with random noise and, guided by the text embedding, progressively refines it into a coherent image.
Here's how it works:
- The process begins with a random 'latent' array (essentially structured noise).
- In each step, the UNet predicts how to alter this array to better match the input text and the visual patterns the model has learned from its training data.
- This continues for a set number of steps (often 50-100 by default).
- Finally, the Image Decoder translates the processed latent array into the final pixel image.
We can visualize this process by decoding the latent array at various steps. The results are striking: early steps show pure noise, but quickly, shapes and outlines emerge, gradually refining into the final image.
The Science Behind Diffusion
The core idea of diffusion models stems from powerful computer vision capabilities. The process can be understood in reverse:
- Start with a clear image and progressively add noise to it over many steps.
- Train a model to predict the noise added at each step.
- To generate new images, start with pure noise and iteratively 'denoise' it using the trained predictor.
This approach allows the model to learn the distribution of visual elements in its training data, not specific images, but general patterns like 'skies are usually blue and above the ground' or 'cats have pointy ears'.
Stable Diffusion's Key Innovation
While the basic diffusion process generates images without text input, Stable Diffusion incorporates text to control the output. Its key speed improvement comes from operating in a compressed 'latent' space rather than directly on pixels, allowing for faster processing and lower memory requirements.
This latent-space approach, combined with its text-guided diffusion process, is what makes Stable Diffusion both powerful and computationally efficient.
Limitations and Open Questions
Despite its impressive capabilities, Stable Diffusion has limitations:
- It can struggle with complex scenes or specific details (like correct numbers of fingers).
- The model's output is influenced by biases in its training data.
- There are ongoing ethical debates about using artists' work without permission for training.
- The technology raises concerns about potential misuse for creating deceptive images.
As AI image generation evolves, these technical and ethical challenges will continue to be important areas of research and discussion.
Related reads
Diffusion Models for Video Generation: Challenges and Approaches
5 min read
Stable Diffusion, DALL-E, Midjourney Recreate Nemesis 2 Graphics
5 min read
DiffusionGemma 26B Model: 4x Faster Text Generation
5 min read
Nano Banana 2 Lite Explained: 4-Second Image Generation, Benchmarks
4 min read
IV-CoT Model Explained: How It Improves Text-to-Image Generation
3 min read
NV-Generate-CTMR Explained: Synthetic 3D Medical Images, Benchmarks
4 min read
Reported and explained by AI·Reporter.