Prefill vs Decode Phases
What prefill and decode mean in an AI request, why each is slow in a different way, and how caching helps, explained for your AI interview.
In short
Prefill is the first stage of an AI request, where the model reads all the input at once. Decode is the second, where it writes the answer one token at a time. Prefill sets how long you wait for the first word, and decode sets how fast the rest arrives.
10 min readIntermediateCommon · estimateFacts checked 26 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.
When I send a prompt to a model, it works in two stages. First is prefill: it reads all my input at once, in one parallel pass, and saves its working notes, the keys and values. Then comes decode: it writes the answer one token at a time, reusing and adding to those notes. Prefill sets how long I wait for the first word. Decode sets how fast the rest comes out. Prefill is limited by raw maths, decode by how fast data moves from memory, so the fixes differ. Caching a shared start skips repeated prefill work.
A language model handles a request in two stages. The first is prefill. The model reads the whole input, the instructions and the document you pasted, all at once. It does that in one big parallel pass, and it keeps the keys and values it computes, which are its working notes on each token. The first new word comes out at the end of this stage.
The second stage is decode. The model writes the answer one token at a time, and each new token needs the notes from every token before it. NVIDIA describes decode as memory-bound, which means the speed of moving data from memory sets the pace, and the chip's maths waits for it. Prefill keeps the chip busy with maths. Decode often leaves much of that compute idle.
So the two stages shape the user's wait differently. Prefill sets how long you wait before the first word. Decode sets how fast the rest arrives. For an insurance claims assistant reading a long policy, most of the wait is prefill, so the fix is to skip repeated reading, for example by caching the policy text that starts every prompt. Some serving systems even run the two stages on separate machines and move the saved notes between them.
In an interview, name the two stages, say which one sets the wait, and say that caching only skips repeated prefill. That answer shows you understand where the time goes.
What are prefill and decode, in plain words?
When you send a model a prompt, it works in two stages. First it reads everything you sent. Then it writes the reply, one piece at a time. The reading stage is called prefill, and the writing stage is called decode. Both run on a GPU, the graphics chip that runs the model.
NVIDIA puts it in one line: "This process involves two phases: the prefill phase and the decode phase." Both happen on every request, but they take different amounts of time and need different kinds of work from the chip.
Picture a triage nurse. She reads the whole patient chart before she says anything. Then she explains the plan one sentence at a time while she checks her notes. For an AI claims assistant reading a 40-page policy, the same two steps happen: it reads the policy first, then writes the summary.
Key words
- Prefill
- The first stage: the model reads all the input at once, in one parallel pass.
- Decode
- The second stage: the model writes the output one token per step.
- Token
- A small piece of text, often part of a word. Models read and write in tokens, so one long word can be several.
- KV cache
- The saved working notes (keys and values) for the tokens so far. Prefill fills it, and decode adds to it as each new token is written.
- TTFT
- Time to first token: how long until the first word of the reply appears.
How do the two phases differ in work and speed?
Prefill is efficient because all the input is known up front. NVIDIA calls it "a matrix-matrix operation that's highly parallelized", which means one big grid-of-numbers multiplication done all at once. That keeps the chip's maths units busy. Decode cannot do that. Each new token depends on the one before, so the steps must run in order.
- Prefill
Lots of maths at once
Every input token goes through one parallel pass. The chip's maths units stay busy, so the work is limited by compute.
- Decode
Little maths, many steps
One new token per step. Each step must read the model's stored numbers and the saved notes from memory, so memory speed sets the pace.
- What you feel
Two different waits
Prefill sets the wait before the first word. Decode sets how fast the rest streams out.
Researchers saw the same split in 2023. The Splitwise paper describes a compute-heavy phase and a memory-heavy phase, and its design splits the two across machines.
“we find that there are two main phases during an LLM inference request: a compute-intensive prompt computation, and a memory-intensive token generation”
Splitwise research paper (2023)
“The speed at which the data (weights, keys, values, activations) is transferred to the GPU from memory dominates the latency, not how fast the computation actually happens.”
NVIDIA developer blog (2023)
The second quote explains decode. The pace is set by how fast data arrives from memory, and the chip's maths waits for it. That is why a faster compute chip alone does not fix a slow decode. NVIDIA also says batching is the simplest way to raise GPU use and throughput. Batching means running several requests together on the same chip. It raises total throughput, but Splitwise notes that "the token generation phase underutilizes compute resources" even with state-of-the-art batching.
Where does the wait come from in a real request?
Take an insurance claims assistant. It reads a policy wording of about 30,000 tokens, plus the claim note (made-up numbers), and writes a 250-token summary for the claims handler. Nothing shows on screen until prefill finishes, so a 6-second reading pass (made up) is 6 seconds of blank screen.
One request, two phases
Policy text and question
a long policy plus a claim note
Prefill
Read all input at once
one parallel pass, GPU kept busy
Keys and values
saved so steps don't redo them
Decode
One token per step
reads the stored numbers each step
Streamed answer
words appear as they are made
- 1All the input goes in together.
- 2One pass saves the keys and values for every input token.
- 3Each new token reuses the saved keys and values.
- 4The answer streams out one token at a time.
Once the first word appears, the 250 decode steps stream out one by one. So the fix for a slow first word is to cut the reading. The policy wording is the same for every claim on that policy, so it can sit at the start of each prompt and be cached. Anthropic describes it like this: "Prompt caching optimizes your API usage by letting the API resume from specific prefixes in your prompts." For long documents, Anthropic says you generally see improved time-to-first-token. The repeated reading is skipped, so the first word comes sooner.
Tip
Caching skips repeated prefill work for a shared start. It does not change the decode steps, so say that when you explain it.
How would you split prefill and decode across machines?
Some serving systems (the software that answers user requests) run prefill and decode on separate machines. The reason: prefill needs strong compute, while decode is limited by memory. Splitwise makes the same point: the writing step does not need the newest chips.
Two machines, one answer
Request arrives
a long prompt from a user
Prefill machine
Read the input
compute-heavy work
Send the saved state
keys and values, sent across
Decode machine
Write tokens one by one
memory-heavy, cheaper GPUs fit
Answer returned
same answer, two machines
- 1The prompt goes to the first machine.
- 2That machine hands over its saved keys and values.
- 3The second machine picks up that state.
- 4Tokens stream back to the user.
The catch is the handover: the saved state has to move from the prefill machine to the decode machine. The paper says it can achieve "1.4x higher throughput at 20% lower cost than current designs". Those results describe that paper's setup, and they do not carry over to every system.
What does the interviewer want to hear?
A strong answer covers
- Two stages: prefill reads the input, decode writes the output.
- Prefill is one parallel pass, and it sets time to first token.
- Decode is one token per step, and memory speed sets its pace.
- The KV cache links them: prefill fills it, decode reuses it and adds to it.
- Caching skips repeated prefill, and it does not speed up decode.
- Serving trade-offs: batching, and splitting the phases across machines.
Common traps
Trap"Prefill is when the model writes the answer."
BetterPrefill reads the input. It ends with the first new token, then decode writes the rest.
Trap"A faster GPU makes the whole answer faster."
BetterDecode is limited by memory speed, so a faster compute chip alone does not fix it. Faster memory helps, and batching serves more users per chip.
Trap"Caching makes every answer faster."
BetterCaching skips repeated prefill on a shared start. It leaves the decode steps as they were.
Can you spot the slow part?
Spot the fix
Your claims assistant takes 9 seconds (made up) before the first word, then streams quickly. Which change cuts that wait the most?
Quick check
Which statement about the decode phase is right?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q055What is the KV cache, and why does it speed up generation?12 min
- Q316TTFT vs tokens/sec vs total latency?12 min
- Q326Prompt cache vs semantic cache vs KV cache?Coming soon
- Q335What is prefill/decode disaggregation?Coming soon
- Q073Walk through one decoder block's forward pass.12 min
Learn it in depth
Last updated on 26 November 2026
Building an assistant where users wait on long documents?
I design and build AI products and agents, including the UI and the system behind them. Book a short call and tell me what your users wait for.