Keyword density formula: the calculation, a worked example, and what to do with the number

The formula, a script that does it, and where density matters.

Published by AI Knows Us · Updated 13 October 2026

The keyword density formula is: keyword density (%) = (number of times the keyword appears / total number of words on the page) x 100. If your keyword appears 12 times on a page of 1,000 words, the density is 1.2 percent. For a keyword of more than one word, count each full phrase as one use and divide by the total word count the same way. That is the whole calculation, and it takes a minute. What matters more is what to do with the number, and the honest answer is: use it to catch overuse, not to hit a target.

The formula, step by step

  1. Copy the visible text of the page, without the menu and footer if you want the density of the article alone.
  2. Count the total words. Any word processor shows this.
  3. Count how many times your exact keyword or phrase appears. Use find.
  4. Divide the second count by the first.
  5. Multiply by 100.

A worked example

Say the page has 1,250 words and the phrase "wooden dining table" appears 10 times.

density = (10 / 1250) x 100 = 0.008 x 100 = 0.8 percent

For a phrase of three words, some tools count the words used by the phrase instead: 10 uses x 3 words = 30 words out of 1,250, which gives 2.4 percent. Both are called keyword density. Pick one method and use it for every page you compare, because the two numbers are not interchangeable.

A quick check with code

If you handle many pages, a short script does the sum.

function density(text, phrase) { const words = text.toLowerCase().match(/[a-z0-9']+/g) || []; const p = phrase.toLowerCase().split(/\s+/); let hits = 0; for (let i = 0; i <= words.length - p.length; i++) { if (p.every((w, j) => words[i + j] === w)) hits++; } return words.length ? (hits / words.length) * 100 : 0;
}

It counts whole phrase matches over the total number of words and returns a percentage.

Is there an ideal density?

You will see targets quoted such as one to two percent. They are rules of thumb that circulate between SEO tools. Google has not published a density figure that ranks a page, and its own starter guide for search tells site owners to write naturally for readers. Treat any fixed percentage as a rough guard rail. A page about wooden dining tables will use the phrase and its relatives often because it is about them, and a page that reads well gets the right density without counting.

The better questions are these:

  • Does the keyword appear in the title, the first paragraph and at least one heading?
  • Do you answer the question the searcher typed, in the first lines?
  • Do related words and phrases appear, such as materials, sizes, care and delivery for a table page?
  • Does the page read well aloud?

Our guide to scoring one page against its query shows how to answer all four in a ten minute review, and the eleven on page techniques put them in order.

Where density does matter: stuffing

Google's spam policies name keyword stuffing explicitly. They describe it as filling a page with keywords or numbers in an attempt to manipulate rankings, and give examples such as repeating the same words or phrases so often that it sounds unnatural and lists of cities or phone numbers added with no value. The policies are on Google Search Central. A density calculation is useful here as a smoke alarm. If a page measures at six or eight percent for its main phrase, it almost certainly reads badly, and a rewrite will help both the reader and the page.

Signs of stuffing

  • The same phrase in every sentence of a paragraph.
  • A block of cities or product names at the bottom of the page.
  • Alt text on images that repeats the keyword rather than describing the image.
  • Text in the same colour as the background. Never do this.

How to fix a page that measures too high

  1. Read the page aloud and mark every place the phrase sounds forced.
  2. Replace half of them with a pronoun, a shorter reference or a different true description: "the table", "this model", "the oak top".
  3. Add information the page lacks, such as dimensions, care and delivery, so the total word count rises with useful content.
  4. Recheck the density, then reread. The number is a check on the writing, never the goal.

How to fix a page that measures zero

A page where the keyword never appears is a bigger problem than one where it appears twice too often. Put the exact phrase in the title, in the first paragraph and in one heading, and write the rest in natural variations. Our keyword research method explains how to pick the phrase that deserves the placement.

Density on long pages and short pages

The same count gives different density on different pages. Ten uses of a phrase on a 400 word page gives 2.5 percent, and ten uses on a 2,000 word guide gives 0.5 percent. Neither is wrong. A short page that answers one narrow question may use its phrase more often, and a long guide that covers a topic from many sides spreads its main phrase out among related terms.

When you compare your page with a page that ranks above it, compare the structure instead of the percentage: where the phrase sits, what sections the page has, what questions it answers and what you are missing. The percentage is a by-product of those choices, and it moves when you fix them.

Questions about the keyword density formula

What is the formula for keyword density?

Occurrences of the keyword divided by the total words on the page, multiplied by 100.

What keyword density should I aim for?

Write for the reader first. If you want a rough guard rail, a main phrase that appears naturally a handful of times per thousand words is typical, and anything that sounds repeated when read aloud should be edited.

Does Google use keyword density to rank pages?

Google has not published a density target. It publishes a spam policy against keyword stuffing and guidance to write naturally.

Should I count variations of the keyword?

Count the exact phrase for the formula. Variations are good writing and improve coverage of the topic, but they do not belong in the exact match count.

Is there a free keyword density checker?

Many SEO tools include one, and the short script above does the same job. Whichever you use, check that it counts whole phrases.

How an assistant reads your keyword

A density figure describes how often a string appears. An assistant answering a question about your topic works differently: it reads what a page says, decides whether the page answers the question, and names the businesses and sources it trusts. A page written to repeat a phrase gives it nothing to quote, while a page with a direct answer in the first lines gives it a sentence. AI Knows Us asks ChatGPT, Gemini and Perplexity the questions your buyers ask and records which pages they quote, so you can see whether the wording you tuned for search is the wording an assistant picks up.

Read next

Or browse the whole archive.

See what AI says about you.

The first scan is free, it needs no account, and it asks the questions your buyers ask.

Free. No card. We ask 5 real buyer questions on 2 AI apps.

Already sure you want this? Join the waitlist. We open on 31 October 2026. It costs an email address. No card, and nothing is charged. Or talk to a person if you have a question first. Or read how we fix what it finds.