There's No Ideal Keyword Density. Here's the Outlier Check I Use Instead (and What It Found in 77 of My Posts)
The most-seen page on postingdude.com is a keyword density checker. In the 28 days to Nov 15 it had 1,494 Google impressions, 0 clicks, and an average position of 47.6. Page five. People were searching "what is a good ke
The most-seen page on postingdude.com is a keyword density checker. In the 28 days to Nov 15 it had 1,494 Google impressions, 0 clicks, and an average position of 47.6. Page five. People were searching "what is a good keyword density" and my page wasn't answering it.
So on Nov 23 I added the honest answer to the page: Google doesn't publish an ideal keyword density. Its spam policies name keyword stuffing (repeating words or phrases until the text reads unnatural) as a violation, and they don't give a number to aim for.
Which left me with an awkward question. If there's no target percentage, what is a density checker actually for? This post is my answer, with the 38 lines of Python I now use and what happened when I pointed it at every long article I've posted here.
Small numbers up front: Posting Dude is one of my small sites, it got 5 clicks from Google in the last 28 days, and I'm a solo founder going full-time indie on a handful of sites like it. This is a tutorial, not a growth story.
The 2% rule I almost wrote
Honestly, my first draft of the page copy said something like "aim for 1-2%". Every other checker says it, and it feels helpful. Then I went looking for where that number comes from and couldn't find it in anything Google has published. It's folklore that got copied from tool to tool.
What the spam policy does describe is a shape: one word or phrase repeated far more than the text needs. That's not a percentage. It's an outlier. So the useful question for a draft isn't "is my keyword at 2%?" It's "does one phrase stick out way above everything else?"
The check: count phrases, compare to the neighbours
The method, in steps you can copy:
- Take the visible text (for my own posts I use the markdown and strip code blocks, image tags and link URLs).
- Count 1-, 2- and 3-word phrases. Skip phrases that start or end with a stopword, so "of the" and "in a" don't win.
- Take the top 9 phrases. For the top one, divide its count by the median count of the next 8.
- If that ratio is 3 or more, go read the paragraphs where that phrase appears. Below 3, move on.
That's it. Here's the script:
#!/usr/bin/env python3
"""phrase_outliers.py - find the phrase that sticks out, not a 'good' density %."""
import re, sys, statistics
from collections import Counter
STOP = set("""a an the and or but if of to in on for with at by from as is are was were be been it its this that
these those you your i my we our they them he she his her not no so do does did can will just than then there here
what which who how when where why all any some more most into out up about over after before also only very""".split())
def words(text):
text = text.lower().replace("\u2019", "'")
return re.findall(r"[a-z0-9][a-z0-9'\-]*", text)
def phrases(ws, n):
out = []
for i in range(len(ws) - n + 1):
g = ws[i:i+n]
if g[0] in STOP or g[-1] in STOP: # skip "of the", "in a" etc.
continue
out.append(" ".join(g))
return out
def report(text, n=2, top=8):
ws = words(text)
counts = Counter(phrases(ws, n))
common = counts.most_common(top + 1)
if len(common) < 3:
return ws, []
med = statistics.median([c for _, c in common[1:]])
return ws, [(p, c, round(100 * c * n / len(ws), 2), round(c / med, 1))
for p, c in common[:top]]
if __name__ == "__main__":
n = int(sys.argv[sys.argv.index("--n") + 1]) if "--n" in sys.argv else 2
ws, rows = report(open(sys.argv[1], encoding="utf-8").read(), n)
print(f"{len(ws)} words, {n}-word phrases")
for p, c, d, x in rows:
print(f"{p:32} {c:>5} {d:>7}% {x:>5}x" + (" <- look at this" if x >= 3 else ""))
Two notes. Density here is count ร phrase length รท total words, which is one common way checkers do it; tools differ, which is another reason not to chase a number. And the 3x threshold is mine, picked by reading the results below. It isn't a Google number either.
First test: the checker's own page
I ran it on the visible text of the keyword density checker page itself (nav and footer included), Dec 1:

The script on the keyword density page, Dec 1 2026. Its own topic phrase is 1.06% and 1.8x its neighbours. Nothing flagged.
"keyword density" appears 12 times in 2,264 words. That's 1.06%, and only 1.8x the median of the next phrases. A page about keyword density that doesn't overuse "keyword density". Good, but not very interesting.
Then I ran it on 77 of my own DEV posts
This is where it got useful. I pulled every article on this account through the DEV API (131 items, 77 of them long enough to count; quickies under 120 words left out) and ran the 2-word check on each.

77 of my DEV articles, Apr-Nov 2026. A "2% rule" and an outlier check disagree on a lot of posts.
What came back:
- 13 posts are over 2%. A 2% rule would have me "fix" all of them.
- 12 posts have a top phrase at 3x or more of its neighbours.
- They aren't the same list. 4 posts are over 2% without sticking out (an "Episode 2" series post, two old "Introducing SideHunt/EarlyHunt" launch posts). 3 posts stick out while sitting under 2%: "rel canonical" in my canonical post, "card testing" in a checkout-fraud post, "next invoice" in a billing post.
Then I actually read the flagged ones, which is the whole point of the check.
The two biggest outliers were fine. My robots.txt post says "robots txt" 25 times (8.3x the next phrases). My open-redirect post repeats one example domain 30 times, 7.96% of the words, because it's a list of test strings. In a technical post, the thing you're explaining is going to stick out. Rewriting those to hit 2% would make them worse.
The one that made me wince was my own. My April post "What is Posting Dude?" says "posting dude" 12 times in 399 words: 6.02%, 6x the next phrases. Reading it now, it isn't a post. It's an ad with headings. No checker setting would have fixed that. What fixes it is having something to say besides the name.
So the rule I'm keeping: the outlier tells you where to look, not what's wrong. If it's the topic noun of a technical post, leave it. If it's your brand name or a phrase you were trying to rank for, that's the paragraph to rewrite.
What I didn't do
I didn't go back and edit the 12 flagged posts. Most of them are fine, and the April one deserves a rewrite from scratch, not a find-and-replace.
I also didn't change the checker's output to show a "good" or "bad" badge. It would be the most-clicked thing on the page, and it would be making up the same number I just said Google never published. If you want to try it on a draft without running Python, the keyword density checker on Posting Dude shows 1-, 2- and 3-word counts side by side so the outlier is easy to spot (it's my tool, so take the recommendation with that in mind).
And the page itself? Locked.
The latest Search Console read I have is the 28 days to Nov 29: 1,739 impressions, still 0 clicks, average position 37.8. Position went from 47.6 to 37.8. I'm not taking credit for that. The change only went out on Nov 23, Google's November core update ran Nov 10-24 and overlaps both windows, and I've locked this page until Dec 21 so I don't keep fiddling with it. Impressions up and clicks flat is a pattern I've written about before, how I read an impressions-up, clicks-flat jump, and the short version is: don't celebrate it.
This is the same habit from my letter on fixing the page Google already shows before building another one: I've stopped adding new tool pages and started improving the ones that already get seen. Next chapter is Dec 21, when the lock opens, with the numbers whatever they are.
Your turn
What does your own writing over-repeat? Run any phrase counter on your last five posts and tell me the top phrase and whether it was the topic or a habit. Mine was my own product's name, which is a bit embarrassing to say out loud.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.