Skip to content

Learn AI · Foundations

What is an LLM?

Large Language Models, explained from first principles — what they are, how they predict tokens, and where the magic and limits come from.

7 min readPublished Feb 2025Updated Apr 2026
LLMFundamentalsTransformer
Edited by The AIKnowHub team · Editorial team

Key takeaways

  • 1LLMs predict the next token, not the next 'word' — tokens are sub-word pieces of text.
  • 2Every output is sampled from a probability distribution; temperature controls how 'creative' the sampling is.
  • 3Context window = how many tokens of input + output the model can attend to at once.
  • 4LLMs don't 'know facts' — they compress patterns from their training data and reproduce them.
  • 5Hallucination isn't a bug — it's the same generation process producing plausible but wrong tokens.

The one-sentence version

A Large Language Model (LLM) is a neural network trained to predict the next token in a sequence of text — and that single capability, scaled up, turns out to be powerful enough to write code, summarize PDFs, and answer questions.

Tokens, not words

LLMs don't read words. They read tokens — short fragments of text. The word "unbelievable" might be split into three tokens like ["un", "believ", "able"]. Tokens are the unit of input and output.

When you send a prompt, the model:

  1. Splits your text into tokens.
  2. Runs those tokens through a stack of transformer layers.
  3. Outputs a probability distribution over every possible next token.
  4. Samples one token from that distribution and adds it to the output.
  5. Repeats until it hits a stop signal.

That loop — token in, token out — is the entire trick.

Why it works

The model is trained on trillions of tokens scraped from the public internet, books, and code. To predict the next token well, it has to learn:

  • Grammar (so the sentence sounds right)
  • Facts (so the content is plausible)
  • Reasoning patterns (so the logic holds up)
  • Style (so the tone matches)

It's not memorizing — it's compressing patterns. The same model that completes "The capital of France is" with "Paris" also completes "def quicksort(arr):" with a working implementation.

Context windows

The number of tokens an LLM can consider at once is its context window. Modern models range from 8K tokens (older GPT-3.5) to 1M+ tokens (Claude, Gemini). Bigger windows mean you can fit more of a codebase, a book, or a transcript into a single prompt.

One nuance: bigger context isn't free. Quality of recall often degrades past ~100K tokens. For long documents, retrieval (RAG) often beats stuffing everything into context.

Temperature, top-p, and sampling

Generation isn't deterministic. After the model produces a probability distribution over the next token, it samples one. The shape of the sampling is controlled by:

  • Temperature — higher = more random. 0 = always pick the highest-probability token.
  • Top-p (nucleus) — only sample from the smallest set of tokens whose cumulative probability passes p.
  • Top-k — only sample from the top k candidates.

For coding and factual tasks, lower temperature (0–0.3). For brainstorming and creative work, higher (0.7–1.0).

What LLMs are bad at

  • Math beyond rough estimates — they predict tokens, they don't calculate. Even modern reasoning models lean on tools for serious math.
  • Knowing what they don't know — they will confidently hallucinate.
  • Anything past their training cutoff unless you give them tools or retrieval.
  • Counting — try asking "how many R's are in 'strawberry'" on a model with no tool use.

What's next

LLMs alone are useful, but the real leverage comes when you combine them with retrieval (RAG), tools (function calling), and memory. Those layers are what turn a clever autocomplete into an actual assistant.

Common misconceptions

The wrong-but-common takes worth correcting.

Myth

LLMs understand language the way humans do.

Reality

They model statistical patterns over tokens. The behavior looks like understanding because the patterns are deep — but the underlying mechanism is prediction, not comprehension.

Myth

Bigger models are always better.

Reality

Quality scales with parameters until task-specific data, training, and architecture matter more. A 70B model fine-tuned on coding can beat a generic 400B on code tasks.

Myth

An LLM can answer anything if you prompt it right.

Reality

It can only answer from what's encoded in its weights or what you give it in context. For private data, you need retrieval (RAG). For current events, you need tools.

Real-world use cases

Frequently asked questions

They're all LLMs from different labs (OpenAI, Anthropic, Google). They differ in training data, alignment, context window, multimodal capabilities, and pricing. See our GPT vs Claude vs Gemini comparison for a head-to-head.

Watch

Hand-picked videos from official + trusted channels. Opens in a new tab.