Free auditStart free
GlossaryGlossary · Keywords and research

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.

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 withChatGPTClaudePerplexityGoogleAI Mode
01Check 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
02At 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.

03Good to know

TF-IDF and Google

Google's guide to its ranking systems 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 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 review. It tells you what other pages say, not what Google rewards.

04Explained

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 and 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. 01Feature extraction: Tf-idf term weighting (scikit-learn)scikit-learn.org · checked 2026-10-25
  2. 02Practical BM25, Part 2: The BM25 algorithm and its variables (Elastic)elastic.co · checked 2026-10-25
  3. 03A guide to Google Search ranking systemsdevelopers.google.com · checked 2026-10-25
  4. 04Spam policies for Google web searchdevelopers.google.com · checked 2026-10-25
Questions

Asked a lot.

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

01What 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.

02Is TF-IDF considered AI?

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

03Does Google use TF-IDF?

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

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

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.

Free · 2 minutes

Know the term. Now check your site.

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

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • +212% organic clicks in 90 days Ledgerly