Preferences

Privacy is important to us, so you have the option of disabling certain types of storage that may not be necessary for the basic functioning of the website. Blocking categories may impact your experience on the website. More information (Cookie Policy)

TF-IDF: What It Is, How It Is Calculated and Where It Is Used

TF-IDF is a score that shows how important a word is in one document compared with a whole collection. Learn the formula, an example and its uses.

Sorank customerSorank customerThomas Girauc, Sorank customerCelio Fabiano, Sorank customerSorank customerXavier Breull, Sorank customer
+ 9'000 Subscribers
TF-IDF: What It Is, How It Is Calculated and Where It Is Used
Notification: your site reached 20K clicks from Google Search in 28 days

Tools

On this page

Summary

TF-IDF is a weighting method that scores how important a word is in one document of a collection. It multiplies term frequency, how often the word appears in that document, by inverse document frequency, which lowers the score of words found in many documents. It is high for words frequent on one page but rare across the others.

Want to go further? Ask

TF-IDF is a simple way to measure how much a word says about one document, compared with the other documents you have. A word that appears often in your page but rarely in other pages gets a high score. A word that appears on every page, like "the", gets a score close to zero. Search engineers and data scientists use TF-IDF to compare texts, and SEO teams use it to see how a page's wording differs from the pages that already rank.

What does the TF part measure?

Term frequency (TF) measures how often a term appears in one document. The raw version is a simple count: if "coffee" appears 4 times on a page, its TF is 4. Long pages naturally repeat more words, so most people divide the count by the total number of words. Four mentions in a 100-word page and 40 mentions in a 1000-word page then give the same relative weight.

What does the IDF part measure?

Inverse document frequency (IDF) measures how rare a term is across the whole collection. You divide the total number of documents (N) by the number of documents that contain the term, called df(t), then take the logarithm of that ratio. If every document contains the term, the ratio is 1 and the logarithm is 0, so the term carries no weight. A term found in only a few documents gets a large weight, which is why TF-IDF pushes generic words down and lifts specific ones.

How is TF-IDF calculated?

TF-IDF is the product of the two parts. For a term t in a document d, you multiply the term frequency of t in d by the inverse document frequency of t in the collection. The most common textbook form looks like this.

tf-idf(t, d) = tf(t, d) × idf(t)
idf(t) = log(N / df(t))

The logarithm base does not change the order of the words within one document, only the scale of the scores. Implementations differ on the details. The scikit-learn user guide documents a smoothed variant of the idf, so check the formula your tool uses before you compare numbers across tools.

The scikit-learn user guide section on TF-IDF term weighting, with the tf-idf formula and the idf and normalization steps
Screenshot of scikit-learn.org

How do you calculate TF-IDF with an example?

Take a collection of 10 product pages (N = 10). The word "coffee" appears in 2 of them, so df = 2. On one 100-word page, "coffee" appears 4 times and "the" appears 6 times.

For "coffee", idf = log10(10 / 2) = log10(5), about 0.699. tf = 4 / 100 = 0.04. So tf-idf = 0.04 × 0.699, about 0.028.

For "the", df = 10 because it is on every page, so idf = log10(10 / 10) = 0. Its tf-idf is 0.06 × 0 = 0, however often it appears.

The page scores high on "coffee" and zero on "the". A number like 0.028 only means something next to the same term on the other nine pages, so always read the scores as a comparison.

Tip

Run this example on three of your own pages in a spreadsheet before you trust any tool. Seeing the numbers move when you add a page makes the idea clear.

How do libraries implement TF-IDF?

Libraries turn a list of raw texts into a matrix of TF-IDF weights, with one row per document and one column per term. The scikit-learn TfidfVectorizer does this in one call, and it normalizes each row to unit length by default (norm='l2'), so every document vector has the same length.

from sklearn.feature_extraction.text import TfidfVectorizer

vectorizer = TfidfVectorizer()
matrix = vectorizer.fit_transform(pages)
The scikit-learn TfidfVectorizer reference page, with its description and parameters such as smooth_idf and norm
Screenshot of scikit-learn.org

Keep the same collection when you compare scores, because the idf part changes every time you add or remove a page.

What is TF-IDF used for?

TF-IDF is used for three main jobs: search, keyword analysis and document similarity. In search, a system scores each document against a query by adding up the weights of the query words it contains. In keyword analysis, it shows which terms make a page distinctive within a topic. For similarity, each document becomes a vector of weights, and the cosine similarity between two vectors tells you how close their topics are. The scikit-learn TfidfVectorizer reference states that once the l2 norm is applied, the cosine similarity between two vectors is their dot product.

How can you use TF-IDF for SEO?

You can use TF-IDF to compare your page with the pages that already rank for a query. Terms that carry high weight across those pages but are missing from your text show gaps in your coverage. TF-IDF works on exact words, so it complements semantic search, which matches meaning. Do not aim for a target score. The weights depend on the pages you compare, so a different set of pages gives different numbers.

Unlike keyword density, which counts one term on one page, TF-IDF weighs that count against the rest of the collection. To check raw counts first, use the free keyword density calculator. Then turn the gaps into a plan with a content brief guide.

At Sorank, the Content Optimization module checks each page of your site and rewrites weak pages at the same address. The topic cluster generator flags overlapping keywords before two of your pages compete for the same query. If you want more tools for this comparison, see the list of the best content optimization tools.

Common TF-IDF mistakes

Four mistakes show up most often. Check for each one before you trust your numbers.

Using a collection that is too small

With only three or four documents, one page can change the idf of every other term, so the scores are unstable. You spot it when a common word suddenly scores high after you add one page. Fix it by comparing against a larger set, such as the 10 to 20 pages that rank for the same query.

Comparing scores across different collections

A score depends on N and on df, so a score from one set of pages cannot be compared with a score from another. You spot it when a table mixes results from two different analyses. Fix it by keeping one collection for the whole comparison, and recalculating every score when the collection changes.

Treating TF-IDF as a ranking factor

Some people assume a higher score means a higher ranking. You spot it when a page is rewritten to hit a target number and reads worse for the visitor. Fix it by using TF-IDF to find missing topics, then writing for the reader. Google has not listed TF-IDF among its ranking signals.

Keeping noise in the text

Menus, footers, cookie banners and stopwords like "and" or "of" add weight to words that carry no topic. You spot it when navigation labels show up in your top terms. Fix it by removing boilerplate and stopwords before you calculate, and by lowercasing the text so "Coffee" and "coffee" count as one term.

Why does TF-IDF matter for SEO and GEO?

TF-IDF matters because it explains how classic search matched documents to queries, and many modern systems still combine that exact-word matching with meaning-based retrieval. It helps you see which terms make your page distinct and which topics your competitors cover that you do not. For GEO, a page that names its specific terms clearly gives AI answer engines something precise to retrieve, and that precision works alongside vector search rather than replacing it.

Conclusion

TF-IDF weighs how often a word appears in one document against how rare it is across the collection. Calculate it with the formula above, keep the collection fixed when you compare, and use the scores to find gaps, not to hit a number. Start with the example, then test it on your own pages.

Sources

Frequently asked questions

What does TF-IDF stand for?

TF-IDF stands for term frequency and inverse document frequency. Term frequency counts how often a word appears in one document, and inverse document frequency measures how rare that word is across the whole collection.

Is TF-IDF still used today?

Yes, it remains a standard baseline in information retrieval and text analysis. Modern search and AI systems rely on many more signals, so use TF-IDF to understand term weighting, not as a formula to copy into your pages.

Can TF-IDF tell me which keywords to add to a page?

It can show which words are distinctive for a page compared with other pages on the same topic. Use it as a diagnostic, then check the wording against what your readers type and what your competitors cover.

Our Blog for Ambitious Company

Testimonials from ambitious founders

0 to 10000 visitors in 5 months

Celio Fabianomonrobotlavevitre.frGoogleE-commerce

0 to 5000 visits in 8 months

Thibault BMsorank.comGoogleSoftware

0 to 1104 clicks in 4 months

Dominiqueflight-sensations-idf.comGoogleLeisure and aviation

0 to 163 clicks in 6 months

Coworking Pariscoworking-paris.frGoogleOffice broker

x92 clicks in 7 months

Guide Zanzibarguidezanzibar.comGoogleTravel