How LLMs Actually Process Your Messages: A Clear Guide to Context Windows, Token Limits, and…
From the publisher’s feed, collected in the ZeroLabs newsroom.
How LLMs Actually Process Your Messages: A Clear Guide to Context Windows, Token Limits, and Conversation FlowA beginner‑friendly explanation of how LLMs handle conversation history and why they sometimes “forget”.Generated by NotebookLM· 1. Introduction· 2. How LLMs Process Your Input ∘ 1. System instructions ∘ 2. Conversation history ∘ 3. Your latest message· 3. What Is a Context Window?· A simple way to visualise it· 4. Step‑by‑Step Walkthrough: How a Model Reads a Conversation ∘ Step 1: You send a new message ∘ Step 2: The system gathers all relevant context ∘ Step 3: It builds one long prompt ∘ Step 4: The model processes the prompt ∘ Step 5: The model generates a response ∘ Flow Diagram (simple and intuitive)· 5. Token Counts Explained (With Realistic Numbers) ∘ A simple example with token counts ∘ Why token math matters ∘ A larger example· 6. What Happens When the Conversation Gets Too Long ∘ 1. Truncate older messages ∘ 2. Summarise older messages ∘ A practical example· 7. Input Token Limits vs Output Token Limits ∘ 1. Input token limit ∘ 2. Output token limit ∘ Why this matters ∘ The key takeaway· 8. Full End‑to‑End Example (Using Our Conversation) ∘ Step 1: Early conversation (small token usage) ∘ Step 2: Conversation grows (token usage increases) ∘ Step 3: Conversation exceeds the limit ∘ Step 4: Model generates a response ∘ Step 5: Next turn repeats the cycle ∘ Why this example matters· 9. Practical Tips for Users and Developers ∘ 1. Keep prompts focused and clean ∘ 2. Summarise long conversations manually when needed ∘ 3. Don’t assume the model remembers anything ∘ 4. Be aware of output token limits ∘ 5. When building apps, control the prompt explicitly ∘ 6. Reset the conversation when needed ∘ 7. Use shorter variable names, shorter examples, and concise instructions ∘ 8. Remember that context windows are not memory1. IntroductionAs part of my Applied Gen AI course at Johns Hopkins University, I’ve been diving deeper into how Large Language Models actually work behind the scenes. I’ve used LLMs for a while, but I realized I didn’t fully understand what happens when I type a message and the model responds. Does it remember everything I said earlier? Does it store the whole conversation somewhere? Or is something else going on?Once I started exploring this topic properly, things finally clicked. LLMs don’t “remember” conversations the way humans do. Instead, they rely on something called a context window, and every response is generated from scratch using whatever text fits inside that window.In this article, I’m documenting what I learned — in simple, practical terms — along with examples and diagrams that helped me understand the process clearly. If you’ve ever wondered how LLMs handle long chats, why they sometimes forget things, or what “token limits” actually mean, this breakdown should help.2. How LLMs Process Your InputOne of the first things I learned is that LLMs are stateless. They don’t store your previous messages internally. Instead, every time you send a new message, the system rebuilds the entire context and sends it to the model as one long prompt.That prompt usually contains three parts:1. System instructionsInstructions or guidelines given to the model at the start (e.g., “You are a helpful assistant”). They’re usually hidden from the user.2. Conversation historyAll previous messages that still fit inside the model’s context window.3. Your latest messageThe new input you just typed.The model receives all of this text at once and generates a response based only on what’s inside that prompt. If something isn’t included, the model has no way of knowing it happened.A simple exampleUser: Who is the CEO of OpenAI? Assistant: Sam Altman. User: Where did he study?Behind the scenes, the system sends something like this to the model:[System]: You are a helpful assistant.[User]: Who is the CEO of OpenAI?[Assistant]: Sam Altman.[User]: Where did he study?Because the earlier messages are included, the model can correctly interpret “he” as Sam Altman.If the system only sent:[User]: Where did he study?The model would have no idea who “he” refers to.This was the moment things started making sense for me — the model doesn’t remember anything unless it’s explicitly included in the prompt. The “memory” is just text.3. What Is a Context Window?One of the concepts that finally made things “click” for me was the context window.A context window is simply the maximum amount of text (in tokens) that an LLM can read at once. Think of it like the model’s short-term memory: it can only hold so much information at once. That includes:the system promptthe entire conversation historyyour latest messageand even the model’s own output (because output also consumes tokens)Different models have different window sizes. Some smaller models support around 4k–8k tokens, while more advanced ones go up to 128k or even 200k tokens. But regardless of size, the rule is the same:The model can only “see” what fits inside its context window. Anything beyond that is invisible to it.This is why LLMs sometimes “forget” things you said earlier in a long conversation. It’s not because the model is confused — it’s because the older messages literally aren’t included in the prompt anymore.A simple way to visualise itThink of the context window as a sliding glass window over your conversation. As the conversation grows:new messages enter from the rightold messages fall out on the leftThe model only sees whatever is inside the window at that moment.This sliding behaviour is what allows you to keep chatting with an LLM, even though the model itself never stores long‑term memory.4. Step‑by‑Step Walkthrough: How a Model Reads a ConversationLet’s walk through using a simple example.Step 1: You send a new messageSay you ask:“Where did he study?”Step 2: The system gathers all relevant contextThe system collects:the system instructionsthe previous messagesyour new messageBut only the parts that fit inside the context window.Step 3: It builds one long promptIt might look like this:[System]: You are a helpful assistant.[User]: Who is the CEO of OpenAI?[Assistant]: Sam Altman.[User]: Where did he study?This entire block is what the model receives. There is no hidden memory — this text is the memory.Step 4: The model processes the promptThe model reads the entire prompt token by token. Because “Sam Altman” appears earlier in the prompt, the model can correctly interpret “he.”If that earlier message had been trimmed out due to context window limits, the model would no longer know who “he” refers to.Step 5: The model generates a responseLLMs generate text one token at a time, predicting the next token based on everything in the prompt. This continues until:the model reaches the output token limitor it decides the answer is completeFlow Diagram (simple and intuitive)Your new message │ ▼System collects:- system prompt- recent history- your message │ ▼Builds full prompt (must fit in context window) │ ▼LLM reads entire prompt │ ▼LLM generates response token by token5. Token Counts Explained (With Realistic Numbers)One thing that really helped me understand context windows was learning how tokens work. Before, I used to think of text in terms of characters or words. But LLMs don’t operate that way — they work with tokens, which are small chunks of text. A token might be a whole word (“cat”), part of a word (“inter‑”), or even punctuation.Once I started thinking in tokens, the behaviour of LLMs became much easier to reason about.A simple example with token countsLet’s take a short conversation and assign approximate token counts:Message Approx Tokens-------------- ------System prompt 50User: “Who is the CEO of OpenAI?” 10Assistant: “Sam Altman.” 5User: “Where did he study?” 6Total = 71 tokensThis is tiny compared to most context windows, so the model can easily process everything.Why token math mattersEvery time you send a message, the system builds a prompt like:SYSTEM + HISTORY + YOUR MESSAGEAll of that must fit inside the model’s context window. If the total exceeds the limit, the system has to trim older messages.A larger exampleImagine a model with an 8,000‑token context window.You’ve had a long conversation:20 messageseach ~300 tokenstotal history = 6,000 tokensAdd:system prompt = 200 tokensyour new message = 100 tokensTotal = 6,300 tokens → fits comfortably.But if the conversation grows to:30 messages × 300 tokens = 9,000 tokensplus system + new message = 300 tokensTotal = 9,300 tokens → exceeds the 8,000‑token limit.At this point, the system must trim older messages until the total fits.6. What Happens When the Conversation Gets Too LongThis was one of the most interesting parts for me. I always wondered why LLMs sometimes lose track of earlier details in a long chat. After learning how context windows work, the answer became obvious.When the conversation grows too long, the system has two options:1. Truncate older messagesThis is the simplest approach. The system removes the oldest messages until the remaining text fits inside the context window.2. Summarise older messagesSome systems generate a short summary of earlier parts of the conversation and include that summary instead of the full text. This helps preserve meaning while reducing token usage.The sliding window effectThe easiest way to visualise this is to imagine a sliding window moving across your conversation:[Old messages fall out] [New messages come in] ◄─────────────── CONTEXT WINDOW ───────────────►The model only sees what’s inside that window at any given moment.A practical exampleLet’s say the context window is 8,000 tokens.Your conversation grows to 9,300 tokens. The system might keep only the last 7,700 tokens, plus:system prompt (200 tokens)your latest message (100 tokens)Total = 8,000 tokens → fits perfectly.Everything older than that is gone.Flow diagram: what happens when the limit is reachedFull conversation (9,300 tokens) │ ▼Exceeds context window (8,000 tokens) │ ▼System trims oldest 1,300 tokens │ ▼SYSTEM + RECENT HISTORY + NEW MESSAGE = 8,000 tokens │ ▼Model generates responseNOTE: The model’s output tokens do NOT count toward the context window before the model generates them. They only count after they are generated and added back into the conversation history.7. Input Token Limits vs Output Token LimitsOne thing that confused me early on was the difference between input token limits and output token limits. I used to think the context window was one big bucket that included both input and output together. But that’s not actually how it works.LLMs have two separate limits:1. Input token limitThis is the maximum number of tokens the model can read at once. It includes:system promptconversation historyyour latest messageAll of this must fit inside the context window.2. Output token limitThis is the maximum number of tokens the model is allowed to generate in its response.These two limits work together, but they’re not the same thing.A practical exampleLet’s say a model supports:128k input tokens4k output tokensIf your prompt (system + history + your message) is 120k tokens, the model can still generate up to 4k tokens in its response.But if your prompt is already 128k tokens, the model has no room to generate a long answer. It might:produce a very short responseor stop earlyor refuse due to token constraintsWhy this mattersUnderstanding this helped me avoid a common mistake: sending extremely long prompts and expecting long, detailed answers.If the input is too large, the output has to shrink.The key takeawayEven if the input completely fills the context window, the model can still generate output because output tokens have a separate limit. However, when the input is extremely large, the model may produce shorter or lower‑quality responses due to reduced internal reasoning capacity. After generating output, the system trims older messages to make room for the new tokens.Once I understood this, the whole system felt much more predictable.8. Full End‑to‑End Example (Using Our Conversation)Step 1: Early conversation (small token usage)You ask:“Who is the CEO of OpenAI?”The model replies:“Sam Altman.”Then you ask:“Where did he study?”Behind the scenes, the system builds this prompt:[System]: You are a helpful assistant.[User]: Who is the CEO of OpenAI?[Assistant]: Sam Altman.[User]: Where did he study?Let’s assign approximate token counts:Component Tokens--------- ------System prompt 50First user message 10Assistant reply 5Second user message 6Total = 71 tokensThis is tiny compared to most context windows, so the model easily handles it.Step 2: Conversation grows (token usage increases)As we keep talking, each message adds more tokens to the history. Eventually, the total might reach something like:System prompt: 200 tokensHistory: 7,700 tokensYour latest message: 100 tokensTotal = 8,000 tokensIf the model’s context window is 8,000 tokens, this fits perfectly.Step 3: Conversation exceeds the limitNow imagine the history grows to 9,300 tokens. The system must trim older messages.It might keep:System prompt: 200 tokensRecent history: 7,700 tokensYour latest message: 100 tokensTotal = 8,000 tokens (fits again)Everything older than that is removed.Step 4: Model generates a responseThe model now generates its output — say 150 tokens. These 150 tokens get appended to the history for the next turn.Step 5: Next turn repeats the cycleOn your next message, the system again:collects system promptcollects recent historyadds your new messagetrims if neededsends the final prompt to the modelThis cycle repeats indefinitely.Why this example mattersSeeing the whole flow end‑to‑end made me realise:LLMs don’t remember anything internallyThe “memory” is just text inside the context windowOlder messages fall out as the conversation growsToken limits shape everything the model can do9. Practical Tips for Users and DevelopersAfter learning how context windows, token limits, and prompt construction actually work, I started adjusting the way I interact with LLMs. These are some practical tips that helped me get better results, both as a user and as someone building small LLM projects.1. Keep prompts focused and cleanThe more unnecessary text you include, the faster you fill the context window. Short, clear prompts give the model more room to reason.2. Summarise long conversations manually when neededIf you’re working on a long chat, occasionally summarising earlier parts helps preserve meaning while reducing token usage.3. Don’t assume the model remembers anythingIf something is important, restate it. This ensures it stays inside the context window.4. Be aware of output token limitsIf you need a long, detailed answer, make sure the output limit is high enough. Otherwise, the model may stop early.5. When building apps, control the prompt explicitlyIf you’re developing with LLMs, you should decide:how much history to keepwhen to summarisehow to structure the system prompthow to manage token budgetsLeaving everything to the default chat interface can lead to unpredictable behaviour.6. Reset the conversation when neededIf the model starts giving short or low‑quality answers, it might be because the context window is full. Starting a new chat gives the model a fresh window to work with.7. Use shorter variable names, shorter examples, and concise instructionsThis is especially important in RAG systems or agent workflows where prompts grow quickly.8. Remember that context windows are not memoryThey are just temporary text buffers. If you need real memory, you have to build it yourself (e.g., vector stores, summaries, or external state).These small adjustments made a noticeable difference in the quality of responses I got from LLMs.Some of my other posts you may find interestingSystem Prompts Explained: How Understanding Them Makes You a Better AI CommunicatorThe 3‑Stage Training Pipeline Behind ChatGPT, Claude, and Gemini (Explained Simply)How LLMs Actually Process Your Messages: A Clear Guide to Context Windows, Token Limits, and… was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.