An n-gram is a contiguous sequence of n items — usually words, but sometimes characters — taken from a text by sliding a window across it. The special cases have names: a 1-gram is a unigram (a single word), a 2-gram is a bigram (two consecutive words), and a 3-gram is a trigram.
Worked example. Take the sentence "the quick brown fox". Its bigrams are: "the quick", "quick brown", and "brown fox" — three of them. In general a text of W words yields W − n + 1 n-grams, so the same four-word sentence has 4 unigrams, 3 bigrams, and 2 trigrams. The window is contiguous and order-sensitive: "brown fox" is a bigram but "the fox" is not, because the words are not adjacent.
N-grams are foundational across text processing. Predictive text and autocomplete estimate the next word from the previous one or two (an n-gram language model). SEO and content research look at which bigrams and trigrams appear most often to find the phrases people actually search for, which is more useful than single-word keyword density because meaning usually lives in phrases. Plagiarism detectors compare overlapping n-grams between documents. Character-level n-grams help with language identification and fuzzy matching. Two practical nuances: n-grams are computed after tokenization, so tokenizer choices about hyphens and punctuation flow straight through; and higher n captures more context but appears far less often, so bigrams and trigrams are the sweet spot for most content work. Explore the most frequent words and phrases in your own text with our word frequency counter.