What is a padding token?

A padding token is a special token used to make sequences in the same batch have equal length.

LLMs often process multiple sequences together for efficiency, but those sequences may contain different numbers of tokens. Padding fills the unused positions in shorter sequences.

Why is padding needed?

Suppose a batch contains two token sequences:

Sequence A → 8 tokens
Sequence B → 5 tokens

To process them together as a rectangular tensor, the shorter sequence can be padded:

Sequence A → 8 real tokens
Sequence B → 5 real tokens + 3 padding tokens

Conceptually:

A: token token token token token token token token
B: token token token token token <PAD> <PAD> <PAD>

Does the model treat padding as normal text?

Usually no.

An attention mask is commonly used to tell the model which positions contain real tokens and which positions are padding.

Conceptually:

Real token     → attend
Padding token  → ignore

This prevents padding positions from influencing the meaningful parts of the sequence.

What does a padding token look like?

Its representation depends on the tokenizer.

It may appear conceptually as:

<PAD>

Internally, it has a reserved token ID.

Some model families have a dedicated padding token, while others may reuse another special token for padding depending on their tokenizer and serving setup.

Left padding vs. right padding

Padding can be added:

  • After the real tokens — right padding
  • Before the real tokens — left padding

For example:

Right padding:
Hello world <PAD> <PAD>

Left padding:
<PAD> <PAD> Hello world

Which approach is appropriate depends on the model architecture and inference implementation.

Is padding always necessary?

No.

A single sequence does not usually need padding.

Some modern serving systems also use techniques that reduce or avoid unnecessary padding when batching variable-length requests.

Padding is mainly useful when sequences must be arranged into equal-sized batches.

For the broader category, see “What are special tokens in an LLM?”

In short: a padding token is a reserved token used to fill unused positions so sequences of different lengths can be processed together efficiently, while an attention mask usually prevents those padding positions from affecting the model's actual computation.

#what is a padding token#padding token LLM#PAD token in LLM#LLM sequence padding#padding token attention mask#large-language-models#llm#tokenization#special-tokens#padding-token

Learning Sequence

Large Language Models Curriculum

18% Completed
Up NextLarge Language Models

What is a token ID?

Explore Related Questions

Deepen your understanding across related Large Language Models topics.

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.