Context windows and prompts
A model sees only what's in its context window, rebuilt by your app on every call. Watch a prompt get assembled, counted and trimmed, and see a key fact fall out.
9 minFree
- Build prompt
- Count tokens
- Trim
- Generate
- Save
Press Play to watch it run, or step through with ← →. Then switch to Practice and run it yourself.
What the model sees
Nothing sent yet. Press Play.
Background: the idea in plain words
A model has no memory between calls. Each request starts from nothing. Yet a chat app seems to remember what you said five minutes ago. How?
What the model can use is the context window: all the tokens (small pieces of text) you send in one request. Google's docs compare it to short-term memory. The app stores the conversation and sends it again with every new message.
In a chat app, the prompt (the full text sent to the model) that the model really sees is usually several parts joined together:
- System instruction: your fixed rules ("You are a trip planner. Keep answers short.").
- Conversation history: earlier messages, sent again every time.
- Extra context: documents, search results or tool results you add.
- The new message from the user.
A tiny example. A traveller tells a trip-planning bot "I'm vegetarian". Many messages later, the traveller asks for dinner ideas. The bot can suggest vegetarian food only if that early message is still inside the prompt.
Many Gemini models have context windows of 1 million tokens or more. Google's docs give examples of what that holds: about 50,000 lines of code, 8 average-length English novels, or transcripts of over 200 podcast episodes. That's a lot, but it isn't free: you pay for every token on every call, and bigger prompts take longer. So an app often sets its own smaller limit and has to choose what to leave out when a chat gets long.
Press Play to watch a short chat. Then switch Try it to Long chat: oldest turns dropped, and finally to keep a summary of key facts.
What to notice
- The model only knows what's in the window. No hidden memory, no other chats. If a fact isn't in the prompt (and wasn't in its training data), the model can't use it.
- "Memory" is your app re-sending history. The bot seems to remember because your code stores each turn and sends it again. See Training an LLM: chatting never changes the model itself.
- What falls out is your choice. Dropping the oldest turns is simple but loses important facts. Summarising old turns, or storing key facts separately, keeps them in far fewer tokens.
- Output counts too. The reply is generated into the same request. On Gemini 4 models, the 1M-token window is shared by input, thinking and output tokens. Earlier Gemini 3 and 2.5 models have separate input and output limits.
- A big window isn't perfect recall. Google's docs report that models find a single fact in a long context very well, but accuracy drops when you need many separate facts from it at once.
Reusing a long context If many requests share the same large context, such as one long manual, look at context caching. Google's docs call it the main optimisation for long-context work: you pay less for cached input tokens than for sending them fresh each time.
Go deeperWords to know
| Word | Meaning in simple words |
|---|---|
| Context window | All the tokens a model can take in one request. It is the only thing the model can see |
| Prompt | The full text your app sends to the model for one request |
| System instruction | Your fixed rules for the model, sent with every request |
| Conversation history | The earlier messages of the chat, which your app stores and sends again |
| Turn | One step of a chat: a user message and the reply to it |
| Token budget | A limit your own app sets on prompt size, to control cost and speed |
Check your understanding
Sources: the official documentation
This lesson is based on the official documentation. Check it for the latest details.
Something wrong or unclear in this lesson? Tell us, it gets fixed.