What Does Ngram Mean? A Simple Guide to N-Grams, Examples, and Uses

Quick Answer
If you've searched for “what does ngram mean,” the short answer is that an n-gram is a sequence of *n consecutive items* taken from a piece of text. These items are usually words or characters. A one-word sequence is called a unigram, a two-word sequence is a bigram, and a three-word sequence is a trigram. Computers use n-grams to recognize language patterns, analyze text, and make predictions in natural language processing (NLP).
Key Takeaways
- The letter n represents the number of consecutive items in a sequence.
- Unigrams contain one token, bigrams contain two, and trigrams contain three.
- N-grams can be created from complete words or individual characters.
- Language models use n-grams to estimate which words are likely to appear next.
- Google Books Ngram Viewer is a tool for exploring historical word and phrase frequency in books.
- N-gram frequency can help analyze text, but it does not automatically indicate content quality or Google rankings.
What Does N-Gram Mean?
An n-gram is a group of consecutive items extracted from a larger sequence. The items can be words, characters, or other units of text.
The letter n represents the number of items in the group. For example, an n-gram with two items is a bigram, while one with three items is a trigram.
Consider this sentence:
“Learning SEO helps businesses grow.”
If we divide it into individual words, we get five tokens:
- Learning
- SEO
- helps
- businesses
- grow
A token is a unit of text that a computer processes. Depending on the system, a token might be a complete word, part of a word, a character, or another text unit.
An n-gram takes a selected number of these tokens and groups neighboring items together without changing their order.
This is important because word order carries meaning. The phrase “businesses help customers” does not communicate exactly the same thing as “customers help businesses.”
N-grams preserve the order of the items they contain, making them useful for examining how language is structured.
Google's Introduction to Large Language Models explains n-grams as sequences used in language processing and introduces their role in language models.
Unigrams, Bigrams, and Trigrams Explained With Examples
The easiest way to understand n-grams is to look at how a sentence changes when we group its words in different ways.
Consider this example:
SEO helps websites attract relevant visitors.
For simplicity, we will treat each complete word as one token and leave out the final punctuation mark.
Unigrams: One word at a time
A unigram contains exactly one token.
The sentence produces six unigrams:
- SEO
- helps
- websites
- attract
- relevant
- visitors
Each word is considered separately. This makes unigrams useful for identifying individual terms and counting how often they appear.
Bigrams: Two consecutive words
A bigram contains two neighboring tokens.
The same sentence produces five bigrams:
- SEO helps
- helps websites
- websites attract
- attract relevant
- relevant visitors
Notice that the second bigram starts with the word that ended the first bigram. The process continues one position at a time.
Trigrams: Three consecutive words
A trigram contains three neighboring tokens.
The sentence produces four trigrams:
- SEO helps websites
- helps websites attract
- websites attract relevant
- attract relevant visitors
Each group contains three words, and the groups overlap as the window moves through the sentence.
Comparing the three types
| N-gram type | Number of words | Sequences produced |
|---|---|---|
| Unigram | 1 | 6 |
| Bigram | 2 | 5 |
| Trigram | 3 | 4 |
The general calculation for a sequence containing L tokens is:
Number of n-grams = L - n + 1, provided L is at least n.
For our six-word sentence:
- Unigrams: 6 - 1 + 1 = 6
- Bigrams: 6 - 2 + 1 = 5
- Trigrams: 6 - 3 + 1 = 4
This formula assumes a simple sliding window, without additional start or end markers.
The important lesson is that increasing n creates longer sequences but fewer possible positions within the same sentence.
Word N-Grams vs. Character N-Grams
N-grams do not have to use complete words. They can also be created from individual characters.
The difference depends on what a text-processing system treats as one item.
Word n-grams
Word n-grams group complete words together.
For example, the sentence “Search engines understand language” produces these bigrams:
- Search engines
- engines understand
- understand language
This approach is useful when studying phrases, word combinations, and language patterns.
Character n-grams
Character n-grams divide text into smaller character sequences.
Take the word:
tropical
Its overlapping character bigrams are:
- tr
- ro
- op
- pi
- ic
- ca
- al
Each group contains two consecutive characters.
Character n-grams can help systems compare similar spellings, identify text patterns, and process variations in words. They can also be useful when dealing with misspellings or languages where word boundaries are difficult to identify consistently.
| Feature | Word n-grams | Character n-grams |
|---|---|---|
| Basic unit | Complete words or word tokens | Individual characters |
| Example | search engines | se, ea, ar, rc, ch |
| Common purpose | Phrase and language analysis | Spelling and character-pattern analysis |
| Main limitation | May miss similarities between differently written words | May capture sequences without meaningful word boundaries |
Neither approach is universally better. The right choice depends on the text and the problem being solved.
For additional technical context, see the Information Retrieval and Search Engines reference, which discusses character-level text processing.
How Do N-Grams Work in Language Models?
One important application of n-grams is statistical language modeling.
A language model estimates how likely a particular sequence of words is. It can use that information to predict what word might come next.
An n-gram language model makes these estimates using a limited amount of preceding context.
For example, imagine that a sentence begins:
“I want to drink a ...”
A language model may estimate that words such as “glass,” “cup,” or “water” are possible next tokens.
An n-gram model uses patterns observed in its training text to estimate these probabilities.
How the probability works
For a bigram model, the prediction depends on the immediately preceding token.
For example:
P(next word = “water” | previous word = “drink”)
The vertical bar means “given that.” The expression asks how likely the word “water” is when the preceding word is “drink.”
A trigram model uses the previous two tokens. A four-gram model uses the previous three.
More generally, an n-gram language model estimates the next token using the preceding n-1 tokens.
This is a simplified statistical approach. It does not mean that a model understands the full meaning of a sentence in the same way a human reader does.
Stanford's Speech and Language Processing textbook, Chapter 3 explains n-gram language models, their probability calculations, and their statistical foundations.
Why do language models count n-grams?
Counting sequences helps a model estimate which word combinations are common in its training data.
For example, suppose a collection of text contains these phrases:
- natural language processing
- natural language understanding
- natural language generation
A system can identify recurring sequences and use their observed frequencies when estimating likely continuations.
A basic statistical model can estimate conditional probabilities using observed counts. In practice, it may also need smoothing, which adjusts estimates to handle sequences that were not observed or were observed very rarely.
This is particularly important because a sequence that does not appear in the training data is not necessarily impossible in real language.
What Is Google Books Ngram Viewer?
Google Books Ngram Viewer is a separate tool that uses the n-gram concept to explore how words and phrases appear in books over time.
It allows users to enter words or phrases and view their relative frequency across a selected book collection and historical period.
Read the official Google Books Ngram Viewer documentation.
The tool can help with questions such as:
- When did a particular expression become more common in published books?
- Did one phrase become more popular than another?
- How did the use of a word change across different periods?
How should you interpret its graph?
The graph does not simply show the raw number of times a phrase appeared in books.
Google explains that the displayed frequency is normalized against the number of books published in each year in the selected corpus. This helps account for differences in the amount of material available across years.
Several settings also affect the results:
- Corpus: The selected collection of books and language.
- Time range: The historical period included in the graph.
- Case sensitivity: Whether capitalization differences are treated separately.
- Smoothing: A moving average that can make changes across neighboring years appear less irregular.
These settings matter when comparing phrases. A graph is evidence about patterns in the selected book collection, not a complete measurement of how every person used a phrase in everyday conversation.
Most importantly, remember the distinction:
| Term | Meaning | Main purpose |
|---|---|---|
| N-gram | A sequence of n consecutive tokens | Analyze text sequences |
| N-gram language model | A statistical model using limited preceding context | Estimate likely next tokens |
| Google Books Ngram Viewer | A historical phrase-frequency visualization tool | Explore word and phrase trends in books |
The three concepts are related, but they are not interchangeable.
Where Are N-Grams Used?
N-grams have applications across several areas of computing and language analysis.
Natural language processing
Natural language processing, or NLP, is the field of computing concerned with working with human language.
N-grams can help NLP systems identify common phrases, examine word patterns, and represent text in a structured form.
For example, a text classification system might use recurring word combinations as features when sorting documents into categories.
Text classification
Text classification assigns text to categories.
A system that identifies spam messages, for example, may examine recurring words and phrases associated with unwanted messages.
Bigrams can capture combinations that individual words may not describe as clearly.
Search and information retrieval
Search and information retrieval systems need ways to represent and compare text.
N-grams can help identify phrase patterns and textual similarities. Character n-grams can also help compare terms that differ slightly in spelling.
However, using n-grams does not by itself establish whether two documents have the same meaning or whether a search engine will rank one above another.
Speech recognition
Speech recognition converts spoken language into text.
Traditional statistical language models have used word-sequence probabilities to help evaluate possible word combinations when interpreting speech.
N-gram models can help distinguish between possible sequences based on how frequently those sequences occur in language data.
Language research
Researchers can use n-gram frequency data to study how expressions change over time or differ between collections of text.
Google Books Ngram Viewer is one accessible example of this application.
The Deep Learning Book provides additional technical context about language modeling and applications of token sequences.
What Are the Limitations of N-Grams?
N-grams are useful, but they do not capture every aspect of language. Understanding their limitations helps prevent incorrect conclusions.
Limited context
A short n-gram contains only a small part of a sentence.
Consider these two sentences:
“The company approved the proposal.”
“The company rejected the proposal.”
Some sequences in the sentences are identical, even though their meanings differ significantly.
A system that relies on a limited selection of n-grams may miss important information elsewhere in the sentence.
Data sparsity
Data sparsity occurs when many possible sequences appear rarely or not at all in the available training material.
As n increases, longer combinations generally become less common.
For example, a common two-word phrase may appear thousands of times, while a particular five-word combination might appear only once.
This makes it harder for a statistical model to estimate reliable probabilities for longer sequences.
Dependence on the source material
N-gram frequencies depend on the text being analyzed.
A collection of scientific papers may contain very different language patterns from a collection of social media posts.
Therefore, results from one dataset should not automatically be treated as representative of every type of writing.
Loss of meaning and context
A sequence of words can reveal a recurring phrase without explaining the writer's intention.
For example, the same words can appear in a positive statement, a negative statement, a question, or a quotation.
N-grams are useful representations of text patterns, but they are not complete representations of meaning.
Tokenization differences
Different software systems may divide text into tokens in different ways.
Punctuation, contractions, hyphenated words, and special characters can affect the results.
That is why an n-gram analysis should explain its tokenization rules rather than assume that every tool processes text identically.
Do N-Grams Matter for SEO?
Yes, n-grams can be useful for understanding text patterns and examining how words appear together. However, their usefulness in text analysis should not be confused with proof of a specific Google ranking factor.
For an SEO professional, n-grams can help explain:
- Which words commonly appear together in a collection of content.
- How a topic is expressed through related phrases.
- How search-related language differs across documents.
- Why analyzing individual keywords may miss important phrase relationships.
For example, the phrase “local SEO services” contains three consecutive words and can be represented as a trigram. It can also be divided into shorter bigrams and individual unigrams.
This is a way to describe the text, not proof that Google requires a particular phrase frequency.
Does using more n-grams improve rankings?
No guaranteed ranking improvement follows from adding more n-grams to a page.
Repeating phrases simply to increase their frequency can make content difficult to read and may result in unnatural writing.
A better approach is to explain the subject clearly, answer the reader's questions, and use terminology where it naturally belongs.
For a broader explanation of how useful information and search intent relate to content quality, read Content Relevance in SEO: What It Means and How to Improve It.
N-gram analysis can help describe language patterns, but it cannot replace editorial judgment or demonstrate how a search engine evaluates a particular page.
Frequently Asked Questions
What does the letter N stand for in n-gram?
The letter N represents the number of consecutive items in a sequence. For example, a bigram contains two items, while a trigram contains three.
What is an example of an n-gram?
In the sentence “I love natural language processing,” the bigrams include “I love,” “love natural,” “natural language,” and “language processing.” Each group contains two consecutive words.
What is the difference between a unigram and a bigram?
A unigram contains one token, while a bigram contains two consecutive tokens. A unigram analyzes individual words; a bigram examines pairs of neighboring words.
Are n-grams always made from words?
No. N-grams can also contain characters or other token types. Character n-grams are commonly used to examine spelling patterns and textual similarities.
What is a trigram in NLP?
A trigram is a sequence of three consecutive tokens. In natural language processing, trigrams can help identify three-word patterns and estimate likely word sequences.
What is Google Books Ngram Viewer used for?
It is used to explore the historical frequency of words and phrases in Google's selected book collections. Users can compare how frequently expressions appeared across different periods.
Are n-grams still useful in modern AI?
Yes. N-grams remain useful for text analysis, statistical language modeling, and certain NLP applications. Modern AI systems also use other approaches, including neural networks and transformer architectures, which can model context differently.
Conclusion
An n-gram is a sequence of a specific number of consecutive items from text. The value of n determines how many words, characters, or other tokens each group contains.
Unigrams examine individual items, bigrams examine pairs, and trigrams examine groups of three. These sequences help computers identify language patterns and support applications such as text classification and statistical language modeling.
It is also important to distinguish an ordinary n-gram from an n-gram language model and Google Books Ngram Viewer. One describes a text sequence, another uses sequence patterns to estimate language probabilities, and the third visualizes historical phrase frequency in books.
Understanding these differences makes n-grams easier to recognize and use correctly in language processing, text analysis, and SEO discussions.
---