Skip to main content
AI & Technology

How ChatGPT Actually Works (What Happens When You Hit Enter)

A clear, jargon-free explanation of how ChatGPT works — how it predicts words, why it sounds so human, why it sometimes makes things up, and what it can't do.

13 min read
Share:
Abstract visualization of a neural network processing language
Credit: Unsplash

You type a question, hit Enter, and a few seconds later a fluent, confident, often genuinely useful answer appears — as if a knowledgeable person were typing back. It feels like magic. It isn't. Under the hood, ChatGPT is doing one deceptively simple thing, over and over, billions of times: guessing the next word.

That sounds almost insultingly basic for something that can write code, explain quantum physics, and draft your emails. But once you understand the "next word" idea — and the clever training that turns it into a helpful assistant — the whole thing stops being mysterious. You'll know why it's so good, why it sometimes confidently makes things up, and how to get better answers out of it.

The One Big Idea: It's a Prediction Machine

At its core, ChatGPT is a large language model (LLM) — a system trained to predict what word comes next in a sequence. Think of it as autocomplete on your phone, scaled up almost beyond comprehension.

Here's the key move. Give the model a sentence with the last word missing, and it doesn't "know" the answer — it calculates a probability for every possible next word and picks one.

Bar chart showing the model assigning probabilities to candidate next words for the prompt 'The cat sat on the ___', with 'mat' highest
For 'The cat sat on the ___', the model scores every possible next word. 'mat' wins — but 'floor' and 'sofa' are plausible too. It picks one, adds it, and repeats.

Then it does something crucial: it adds that word to the sentence and predicts the next one. And the next. And the next. Your entire ChatGPT answer — every paragraph, every line of code — is built one word at a time, each new word chosen based on everything that came before it. It's writing the way you might lay down stepping stones across a river: place one, see where you are, place the next.

How It Learned: Reading the Internet and Playing Fill-in-the-Blank

So how does it know that "mat" is more likely than "helicopter"? It learned by example — at staggering scale.

During training, the model was shown an enormous slice of human text: books, articles, websites, conversations, code. For each piece, it played a relentless game: cover the next word, guess it, check the real answer, adjust. Get it wrong, and the model's internal settings (its billions of "parameters") nudge slightly so it does better next time.

Repeat that billions of times across nearly all the text humanity has put online, and something remarkable happens. To predict the next word well, the model is forced to absorb patterns about grammar, facts, reasoning, tone, and style. Nobody programmed it with rules of English or a list of facts. It soaked them up as a side effect of getting good at the guessing game.

This is why the analogy of a "database it looks things up in" is wrong. ChatGPT has no stored table of facts to query. It has a vast web of statistical patterns. When it tells you the capital of France, it isn't retrieving a record — it's predicting that "Paris" is the overwhelmingly likely word to follow that question, because that pattern appeared everywhere in its training.

The Trick That Made It Work: Attention

Next-word prediction is the goal. But there's a mechanism question hiding in the phrase "based on everything that came before it" — how does the model decide which earlier words actually matter?

For years, language models processed text strictly in order, passing a running summary forward word by word. That worked poorly over long distances: by the end of a paragraph, the beginning had been squeezed into a fuzzy blur.

The breakthrough came in 2017, in a paper titled — memorably — "Attention Is All You Need". It introduced the Transformer, an architecture built entirely on a mechanism called attention, discarding the sequential processing that came before.

Attention lets every token look directly at every other token in the input and decide, for each one, how relevant is this to me right now? Consider:

"The animal didn't cross the street because it was too tired."

To handle "it" correctly, the model must connect it to "animal", not "street". Attention does exactly that: when processing "it", the model assigns a high relevance weight to "animal" and low weights to most other words. No rule about pronouns was programmed — the weights were learned.

Diagram illustrating the attention mechanism. The sentence 'The animal did not cross the street because it was too tired' is laid out as tokens. The token 'it' is highlighted, with lines of varying thickness connecting it to the other tokens: a thick line to 'animal' labelled high relevance, a thin line to 'street' labelled low relevance, and a medium line to 'tired'. A note explains that when processing 'it' the model weighs how relevant every other token is, and that these weights are learned rather than programmed. A footer states the mechanism comes from the 2017 Transformer paper and that the weights shown are illustrative.
Attention in one picture: to resolve 'it', the model weighs every other word for relevance and leans heavily on 'animal'. Nobody wrote a grammar rule — the weights were learned from data.

Two things made this transformative. It handles long-range relationships far better, because any two words can connect directly rather than through a chain of intermediate summaries. And because those comparisons happen in parallel rather than strictly in sequence, models became dramatically faster to train — which is precisely what made training on internet-scale text practical in the first place.

Every major model behind today's chatbots, ChatGPT included, is a descendant of that architecture. The "GPT" in the name stands for Generative Pre-trained Transformer.

Words Into Tokens

One small technical wrinkle worth knowing: ChatGPT doesn't actually work with whole words. It breaks text into tokens — chunks that are often a word, but sometimes a piece of one. "Cat" might be one token; "unbelievable" might split into "un," "believ," and "able."

This is why the models sometimes stumble on tasks like counting letters in a word or doing exact spelling — they literally don't see individual letters the way you do. They see tokens. It's a useful thing to remember when an answer seems oddly off for something "simple."

From Raw Predictor to Helpful Assistant

A model trained only to predict text is powerful but unruly — ask it a question and it might continue with more questions, because that's a plausible continuation. Turning that raw engine into the polite, helpful ChatGPT took a second stage.

StageWhat happensResult
PretrainingPredict the next word across massive textKnows language, facts, patterns — but is undirected
Fine-tuningTrained on example conversations done wellLearns to answer, not just continue
Human feedback (RLHF)People rate responses; the model learns which are preferredBecomes helpful, harmless, and on-topic

That last step — reinforcement learning from human feedback (RLHF) — is the secret sauce that made ChatGPT feel like an assistant rather than a strange autocomplete. Humans showed it which kinds of answers were helpful, honest, and safe, and the model learned to favour them.

How much does that shaping matter? More than raw size, it turns out. In the research that introduced the approach behind ChatGPT, OpenAI found that human raters preferred the outputs of a 1.3-billion-parameter model trained with human feedback over those of the 175-billion-parameter GPT-3 — a model over 100 times larger. The smaller, better-aligned model also scored higher on truthfulness and produced less toxic output.

That result reframes the whole story. Scale gave these models their raw capability, but it was the feedback stage that made them useful. A bigger model is not automatically a better assistant.

Why It Sometimes Makes Things Up

Here's the most important thing to understand about ChatGPT, and it follows directly from how it works: it is designed to produce plausible text, not true text.

When the model doesn't "know" something, it doesn't stop — it has no internal signal that says "I'm unsure." It simply predicts the most likely-sounding next words and keeps going. The result can be a confident, fluent, completely fabricated answer: a fake citation, a made-up statistic, an invented quote. This is called a hallucination, and it's not a bug you can fully patch away — it's a side effect of a system whose only job is "what word probably comes next."

The practical lesson: ChatGPT is brilliant at language and reasoning, but it is not a reliable source of facts. Treat it as a fast, articulate assistant whose claims — names, numbers, dates, quotes, legal or medical specifics — you verify before trusting.

What "Memory" Really Means: The Context Window

ChatGPT seems to remember your conversation, but it has no memory in the human sense. Each time it replies, it re-reads the whole conversation so far — your messages and its own — as the input for its next prediction. This visible-at-once span is called the context window.

That's why a long conversation can make it "forget" something from way back: once the chat grows beyond the window, the earliest parts fall out of view. And it's why pasting relevant background directly into your prompt works so well — you're putting the information right where it can see it.

How to Get Better Answers (Now That You Know How It Works)

Understanding the machine makes you better at using it:

  • Give it context. It can only work with what's in the window. Paste the relevant text, examples, or constraints rather than assuming it knows.
  • Be specific about the output you want. Format, length, tone, audience. You're steering the prediction — vague prompts get generic continuations.
  • Show, don't just tell. Give one example of what "good" looks like. Models are exceptional at matching patterns.
  • Verify anything factual. Especially numbers, names, citations, and anything high-stakes. Ask it to flag uncertainty, but don't rely on it to know what it doesn't know.
  • Iterate. Treat the first answer as a draft and refine. "Make it shorter," "more formal," "add an example" all work well.

Common Myths

Myth: "It thinks/understands like a person." It models patterns in language with astonishing fluency, but there's no inner understanding, beliefs, or awareness behind the words. It's prediction, not comprehension.

Myth: "It searches the internet for answers." The base model doesn't — it generates from patterns learned during training. (Some versions can use separate tools to browse or run code, but that's an added feature, not how the core model works.)

Myth: "If it sounds confident, it's correct." Confidence and correctness are unrelated here. Fluent delivery is what it's optimized for; truth is not guaranteed.

Myth: "It's frozen and never wrong about recent events." Its knowledge reflects its training data and has a cutoff. Without a live tool, it won't reliably know yesterday's news.

Frequently Asked Questions

Is ChatGPT just autocomplete?

In mechanism, essentially yes — it predicts likely next tokens, one at a time. But the comparison undersells what happens at scale. To predict text well across billions of examples, the model is forced to internalise grammar, factual associations, translation, tone and multi-step reasoning patterns. Those abilities weren't programmed and weren't the goal; they emerged as side effects of getting very good at the guessing game. Phone autocomplete predicts your next word. This predicts the next word in an argument, a proof, or a working function.

What is a transformer, and why does it matter?

The transformer is the architecture nearly every modern language model is built on, introduced in 2017. Its key mechanism is attention, which lets every word in the input directly weigh how relevant every other word is, rather than passing a running summary forward in sequence. That handles long-range connections far better and — crucially — runs in parallel, which is what made training on internet-scale text practical. The "T" in GPT stands for Transformer.

Why does ChatGPT make up facts?

Because it generates the most plausible-sounding continuation, not verified truth, and it has no internal signal that reads "I don't know this." When the right pattern isn't there, it doesn't stop or hedge — it produces fluent text anyway, which can mean a fabricated citation, an invented statistic or a misattributed quote. This is called hallucination, and it follows from the design rather than being a bug that can be fully patched away. Verify anything factual.

Does ChatGPT learn from my conversations?

Not during the conversation. The model's parameters are fixed once training finishes; within a chat it is only re-reading your context window each turn, which is why it can seem to learn and then "forget" once the conversation outgrows that window. Whether your chats are later used to train future versions is a separate question governed by the provider's settings and tier — business and enterprise tiers typically exclude your data from training by default, consumer tiers historically have not.

Why is it bad at counting letters or simple math sometimes?

Two reasons compound. It reads text as tokens — chunks that are often whole words or word fragments — so it does not see individual letters the way you do, which makes tasks like "how many r's are in this word" oddly hard. And it predicts rather than calculates: arithmetic is generated as plausible-looking text rather than computed. That's why answers can be confidently wrong in the middle of an otherwise correct calculation, and why tool use or a calculator is the right fix.

Can it replace experts?

No, though it can make experts considerably faster. It's excellent for drafting, explaining, summarising and brainstorming — work where you can judge the output yourself. The limit is that it can be confidently wrong without signalling it, so anything with real consequences (medical, legal, financial, safety) needs someone qualified to verify it. The most durable way to use it is as a tireless assistant whose work you review, not as an authority you defer to.

The Bottom Line

ChatGPT is not a thinking mind and not a fact database. It's a spectacularly capable next-word prediction engine, trained on humanity's text and then shaped by human feedback into a helpful assistant. That single idea explains everything that delights us about it — the fluency, the range, the creativity — and everything that trips us up — the confident hallucinations, the shaky math, the missing recent knowledge.

Used with that understanding, it's one of the most useful tools ever built: a tireless, articulate collaborator. Just remember who's responsible for checking the facts. That part is still your job.

Sources

Related on PrimusSource: The AI Landscape Explained: From Machine Learning to AI Agents, Your Brain vs an LLM: Are They Trained the Same Way?, AI Agents Explained: A Practical Beginner's Guide and Will AI Replace Google Search? The Honest Answer Is More Complicated — more in our ChatGPT topic hub.

ChatGPTArtificial Intelligence & LLMs#how chatgpt works#large language models#how ai works#llm explained#artificial intelligence#next word prediction
Share: