# TF-IDF

> TF-IDF is a term weighting scheme from information retrieval. See the formula with a worked example, how BM25 differs, and what Google has not said about it.

Canonical: https://scaplet.com/glossary/tf-idf

Glossary Glossary · Keywords and research

TF-IDF is a term weighting scheme from information retrieval. See the formula with a worked example, how BM25 differs, and what Google has not said about it.

3 min

read

4

sources

Oct 23, 2026

updated

Scaplet Editorial Team

author

In one line

TF-IDF (term frequency times inverse document frequency) weights a word by how often it appears in a document and how rare it is across a collection. It was developed as a ranking function for search engines and is now also used for classification and clustering. Google's documentation does not name TF-IDF as a ranking system.

30-second check

## Is this costing your site traffic?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Ftf-idf%20(%22TF-IDF%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Ftf-idf%20(%22TF-IDF%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Ftf-idf%20(%22TF-IDF%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Ftf-idf%20(%22TF-IDF%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 4 parts, 3 minutes.

1. [What TF-IDF measures 01](#what-tf-idf-measures)
2. [A worked example 02](#a-worked-example)
3. [TF-IDF and Google 03](#tf-idf-and-google)
4. [How it differs from BM25 04](#how-it-differs-from-bm25)

_01_Check it

## What TF-IDF measures

The scikit-learn documentation explains the problem it solves. In a large text corpus, some words are very present, like "the", "a" and "is" in English, and carry very little meaningful information about a document's contents. Raw counts let those frequent terms shadow rarer, more interesting ones. TF-IDF re-weights the counts.

scikit-learn then normalizes the vector by its Euclidean norm. These are scikit-learn's default settings; other tools may use variants, so compare scores only within one tool.

tf-idf, as scikit-learn documents it

```
tf-idf(t,d) = tf(t,d) x idf(t) idf(t) = log((1 + n) / (1 + df(t))) + 1 tf(t,d) = times term t occurs in document d n = total documents in the set df(t) = documents that contain term t
```

_02_At a glance

## A worked example

scikit-learn's own example uses six documents. With the default smoothing, a term present in all six has idf of log(7/7) + 1 = 1. With a count of 3 in document 1, its raw tf-idf is 3 x 1 = 3. A term in two documents with a count of 1 gets 1 x (log(7/3) + 1), about 1.8473. (Without smoothing, the same term scores about 2.0986.)

Term

### Term 1

Count in doc 1

3

Documents containing it

6 of 6

Raw tf-idf (default smoothing)

3

Term

### Term 2

Count in doc 1

0

Documents containing it

1 of 6

Raw tf-idf (default smoothing)

0

Term

### Term 3

Count in doc 1

1

Documents containing it

2 of 6

Raw tf-idf (default smoothing)

about 1.8473

The lesson: a word that appears everywhere gets the smallest multiplier, and a rare word that is present in the document gets a bigger one. A word that is absent scores zero however rare it is.

_03_Good to know

## TF-IDF and Google

Google's guide to its [ranking systems](/glossary/ranking-factors) does not mention TF-IDF, and we found no Google page that says it uses TF-IDF scores to rank pages. So do not describe a TF-IDF score as a Google ranking factor. Its spam policies define [keyword stuffing](/glossary/keyword-stuffing) as filling a page with keywords to manipulate rankings, and lists "Repeating the same words or phrases so often that it sounds unnatural." as an example.

TF-IDF tools used for SEO usually compare the words on your page with words on top-ranking pages. That can show topics a competitor covers and you skip, which is useful for a [content gap](/glossary/content-gap) review. It tells you what other pages say, not what Google rewards.

Do not turn a gap list into a quota

Adding every suggested term to reach a score is [keyword stuffing](/glossary/keyword-stuffing) with extra steps. Add a term when the page really needs to cover that idea.

_04_Explained

## How it differs from BM25

Elastic's explanation of the BM25 algorithm notes that the IDF formula in BM25 differs from the one in TF/IDF. BM25 also uses a parameter, k1, that determines term frequency saturation: it limits how much a single query term can affect a document's score. Elastic says k1 defaults to 1.2 in Elasticsearch. In scikit-learn's default TF-IDF, the count is multiplied in directly, so a higher count keeps raising the weight.

Both are lexical methods that match on words. [Semantic search](/glossary/semantic-search) and [embeddings](/glossary/embeddings) compare meaning instead, and can match a document that shares no words with the query.

Sources · 4

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- scikit-learn.org
- elastic.co
- google.com

1. 01 [Feature extraction: Tf-idf term weighting (scikit-learn)](https://scikit-learn.org/stable/modules/feature_extraction.html) scikit-learn.org · checked 2026-10-25
2. 02 [Practical BM25, Part 2: The BM25 algorithm and its variables (Elastic)](https://www.elastic.co/blog/practical-bm25-part-2-the-bm25-algorithm-and-its-variables) elastic.co · checked 2026-10-25
3. 03 [A guide to Google Search ranking systems](https://developers.google.com/search/docs/appearance/ranking-systems-guide) developers.google.com · checked 2026-10-25
4. 04 [Spam policies for Google web search](https://developers.google.com/search/docs/essentials/spam-policies) developers.google.com · checked 2026-10-25

Questions

## Asked a lot.

4 questions people ask next, answered from the sources on this page.

_01_ What is the formula for TF-IDF?

tf-idf(t,d) = tf(t,d) x idf(t), where tf is how often term t occurs in document d. scikit-learn computes idf(t) as log((1 + n) / (1 + df(t))) + 1 by default.

_02_ Is TF-IDF considered AI?

It is a formula over word counts. scikit-learn calls it a term weighting scheme developed for [information retrieval](/glossary/information-retrieval) that has also found use in document classification and clustering.

_03_ Does Google use TF-IDF?

Google's documentation does not say so. Its ranking systems guide does not mention it.

_04_ What is the difference between TF-IDF and keyword density?

[Keyword density](/glossary/keyword-density) looks at one term's share of the words on a page. TF-IDF also weights each term by how common it is across a collection of documents.

## Keep learning

[All glossary](/glossary)

[Learn LSI keywords Quality and policies](/glossary/lsi-keywords) [Related Keyword stuffing On-page SEO](/glossary/keyword-stuffing) [Read next Embeddings AI search](/glossary/embeddings) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in glossary
[Technical SEO](/glossary/technical-seo) [Temperature](/glossary/temperature) [Thin content](/glossary/thin-content) [Time to First Byte (TTFB)](/glossary/time-to-first-byte)

More in Keywords and research
[Branded keywords](/glossary/branded-keywords) [Competitor analysis](/glossary/competitor-analysis) [Content gap](/glossary/content-gap) [Head terms](/glossary/head-terms) [Keyword difficulty](/glossary/keyword-difficulty) [Keyword mapping](/glossary/keyword-mapping) [Keyword research](/glossary/keyword-research) [Long-tail keywords](/glossary/long-tail-keywords) [Non-branded search](/glossary/non-branded-search) [Pillar page](/glossary/pillar-page) [Search intent](/glossary/search-intent) [Search query](/glossary/query) [Search volume](/glossary/search-volume) [Seed keywords](/glossary/seed-keywords) [SERP analysis](/glossary/serp-analysis) [Striking distance keywords](/glossary/striking-distance-keywords) [TF-IDF](/glossary/tf-idf)

Terms on this page
[Ranking factors](/glossary/ranking-factors) [Keyword stuffing](/glossary/keyword-stuffing) [Content gap](/glossary/content-gap) [Semantic Search](/glossary/semantic-search) [Embeddings](/glossary/embeddings) [Information retrieval](/glossary/information-retrieval) [Keyword density](/glossary/keyword-density)

Free · 2 minutes

## Know the term. _Now check your site._

The free audit reads robots.txt, sitemaps, status codes, canonicals, redirects and structured data.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **+212%** organic clicks in 90 days Ledgerly
