How does AI actually work?
Last updated: May 2026
When you type a question into ChatGPT and it answers in fluent, confident prose, it feels like there's someone in there. There isn't. What's actually happening is stranger and, once it clicks, much simpler than most people expect. Here's the whole thing, explained without the maths.
Let's clear up the big misconception first. When an AI chatbot answers you, it is not looking up facts in a database. It is not thinking through your question the way a person would. It is doing one thing, over and over, very fast: guessing the next word.
That sounds too simple to be true. How could "guess the next word" produce essays, working code, translation, and what looks like reasoning? The answer is one of the more surprising results in modern science, and it's worth understanding properly. So let's build it up piece by piece.
It starts with autocomplete
You already use a tiny version of this technology. When your phone suggests the next word as you type a message, it's making a prediction based on what usually comes next. Type "I'll be there in five" and it offers "minutes." That's the same core idea that powers ChatGPT, just enormously scaled up.1
A large language model, which is the technical name for the thing behind ChatGPT, Claude, and Gemini, is essentially an autocomplete of staggering power. Give it some text, and it predicts what should come next. Then it adds that prediction to the text and predicts again. And again. One piece at a time, it writes its way to a full answer.
Words are actually "tokens"
One small correction to what I just said. The model doesn't quite work in words. It works in tokens, which are chunks of text that are often whole words but sometimes pieces of words.2
For example, the word "playing" might be one token, or it might be split into "play" and "ing," depending on the system. Common words are usually single tokens. Rarer words get broken into parts. This is just a practical way of chopping language into manageable, reusable pieces, so the model can handle words it has never seen by assembling them from familiar fragments.
How it learned: predicting the next token, billions of times
So how does a model learn what comes next? Here's the elegant part. You take an enormous amount of text, essentially a large slice of the public internet, books, articles, and so on. Then you play a simple game with the model, billions of times.
You show it a stretch of real text with the next token hidden, and ask it to guess. Then you reveal the real answer. If the model guessed wrong, you nudge its internal settings slightly so it would do a bit better next time. Repeat this across trillions of words and something remarkable happens.3
Because the text it learns from is written by humans discussing every subject imaginable, guessing the next word well requires the model to absorb a huge amount along the way: grammar, facts, writing styles, the structure of an argument, the format of a recipe, the rhythm of a poem. As one clear explanation from the researcher Sebastian Raschka puts it, the model isn't learning a single fixed rule for the next word. Over many documents it gradually captures syntax, meaning, style, and factual associations.3
The technical name for this training method is self-supervised learning, and the "self" part is the clever bit. Nobody has to label the data by hand. The text supervises itself, because the correct answer is simply the word that actually came next.4
The moment of answering
Now picture what happens when you actually send a message. Your text becomes the starting sequence. The model reads it and produces, for its entire vocabulary, a set of probabilities: how likely each possible next token is.5
Say you type "The capital of France is." The model calculates that "Paris" is overwhelmingly the most probable next token, with everything else far behind. It picks a token, adds it to the sequence, and repeats the whole process for the token after that. This one-at-a-time generation has a name: it's called being autoregressive, which just means each new piece depends on everything written so far.2
Interestingly, the model doesn't always pick the single most likely token. If it did, its writing would be repetitive and stiff. Instead there's usually an element of controlled randomness, which is why asking the same question twice can give you slightly different answers. That variability is deliberate. It's what makes the output feel natural rather than robotic.
What's a "transformer," and why does everyone mention it?
You'll often hear the word transformer attached to all this. (It's the "T" in GPT.) You don't need the maths, but the core idea is worth having.
Earlier language software read text strictly left to right, one word after another, which made it slow and forgetful over long passages. The transformer, introduced by Google researchers in 2017, added a mechanism called attention that lets the model weigh how much every word in a sentence relates to every other word, all at once.6 When it reads "the trophy didn't fit in the suitcase because it was too big," attention is what helps it work out that "it" means the trophy, not the suitcase.
Why it sometimes makes things up
Understanding the "guess the next word" mechanism explains one of AI's most notorious flaws: it confidently invents things. These are often called hallucinations.
Once you know how the machine works, hallucinations aren't mysterious. The model isn't retrieving facts. It's producing text that is statistically plausible given your prompt. Usually plausible and true line up, because true statements are what appeared most in its training. But when they don't, the model will happily generate a confident, well-formed, completely made-up answer, because a fake citation and a real one look equally plausible token by token. The machine has no separate sense of "is this actually true." It only has "does this look like the kind of thing that comes next."
This is also why AI writing has recognisable habits, the smooth phrasing and predictable structures that come from a system optimised to produce the most likely words. If you're curious about those habits, we've written separately about the patterns AI writing tends to leave behind.
The short version
So, stripped all the way down, here's how a chatbot works. It was trained by playing "guess the next chunk of text" across a vast amount of human writing, adjusting itself trillions of times until it got good at it. When you talk to it, it reads your words and generates a reply one token at a time, each time picking a likely next token based on everything so far. Its ability to pay attention to how all the words relate is what keeps the output coherent.
There's no understanding in the human sense, no beliefs, no lookup of stored facts. There's a very, very good next-word guesser that has read more than any person ever could. That it produces something as useful as it does, from a foundation this simple, is genuinely one of the surprises of the last decade.
Sources
- "How Large Language Models Learn to Predict," Medium (2025) — medium.com
- "How Large Language Models Really Work: Next-Token Prediction at the Core," WWW Insights (2025) — wwwinsights.com
- Sebastian Raschka, "How does next-token prediction train a large language model?" (2026) — sebastianraschka.com
- "Next-Token Prediction Explained," QuarkAndCode, Medium (2026) — medium.com
- Cameron R. Wolfe, "Next-token prediction" thread (research summary) — x.com
- Vaswani et al., "Attention Is All You Need" (2017), the paper introducing the transformer architecture.