How ChatGPT and Other Chatbots Actually Work
Beginner to Intermediate 8 min read Updated November 2026
Tokens, Transformers, training and why chatbots sometimes make things up: how large language models work, step by step.
When you type a question into ChatGPT, Claude or Gemini, a reply streams back in seconds, often surprisingly good. Here's what's actually happening behind the curtain.
Step 1: Text becomes tokens
Language models don't read letters or whole words. Your message is chopped into tokens: common words, pieces of words and punctuation. "Unbelievable!" might become "Un", "believ", "able" and "!". Each token is turned into a list of numbers the model can do math on. (That's also why chatbots are sometimes oddly bad at counting letters.)
Step 2: A giant prediction machine
At its core, a large language model does one thing: given some text, it predicts what token is likely to come next. It picks one, adds it to the text, and repeats. Token by token, a whole answer appears.
That sounds simple, but predicting the next word well across billions of documents requires learning grammar, facts, writing styles, code, and patterns of reasoning. Modern LLMs have billions of parameters, the adjustable numbers that store what they learned.
Step 3: The Transformer and attention
LLMs are built on the Transformer architecture, introduced by Google researchers in 2017. Its key trick is self-attention: for every token, the model looks at all the other tokens and decides which ones matter most for interpreting it. In "The trophy didn't fit in the suitcase because it was too big," attention helps link "it" to "trophy."
Step 4: Training in three phases
- Pre-training: the model reads a massive amount of text from books, websites and code, learning to predict the next token. This takes thousands of GPUs and weeks or months.
- Instruction tuning: it's fine-tuned on examples of helpful conversations so it answers questions instead of just continuing text.
- Feedback training: with RLHF and similar methods, people rank answers and the model learns to give responses that are more helpful, honest and safe.
Why answers vary
The model doesn't always pick the single most likely token. It samples from a probability distribution, and a setting called temperature controls how adventurous it is. That's why asking the same question twice can give different wording.
Why chatbots make things up
A language model is optimized to produce plausible text, not to verify facts. When it doesn't know something, it may still generate a confident-sounding answer. These hallucinations include fake citations and wrong numbers. Tools help: many assistants now search the web or use retrieval-augmented generation to ground answers in real sources, and they can run code or call calculators (tool use).
Memory and the context window
A chatbot "remembers" your conversation because the whole chat is sent back to the model each turn, up to its context window limit. Some apps add separate memory features, but the model itself doesn't permanently learn from your chat in real time. It also has a knowledge cutoff, so it won't know about recent events unless it can search.
Using chatbots well
- Be specific about the goal, audience, format and length.
- Give context and examples. Read our Prompting 101 guide.
- Verify facts, numbers and citations for anything important.
- Don't paste in passwords or sensitive personal data.
Think you've got it? Try the Medium quiz. It's full of LLM questions.