Keyword density is the percentage of times a keyword or phrase appears on a web page compared to the total number of words on the page. In the context of search engine optimization, keyword density can be used to determine whether a web page is relevant to a specified keyword or keyword phrase.
In the late 1990s, the early days of search engines, keyword density was an important factor in page ranking. However, as webmasters discovered how to implement optimum keyword density, search engines began giving priority to other factors beyond the direct control of webmasters. Today, the overuse of keywords, a practice called keyword stuffing, will cause a web page to be penalized.
The formula to calculate your keyword density on a web page for SEO purposes is
(Nkr/Tkn)*100
When calculating the density of a keyword phrase, the formula would be
(Nkr*Nwp/Tkn)*100
From a mathematical viewpoint, the original concept of keyword density refers to the frequency (Nkr) of appearance of a keyword in a dissertation. A "keyword" consisting of multiple terms, e.g. "blue suede shoes," is an entity in itself. T frequency of the phrase "blue suede shoes" within a dissertation drives the key(phrase) density. It is "more" mathematically correct for a "keyphrase" to be calculated just like the original calculation, but considering the word group, "blue suede shoes," as a single appearance, not three:
Density = (Nkr / Tkn) * 100.
'Keywords' (kr) that consist of several words artificially inflate the total word count of the dissertation. The purest mathematical representation should adjust the total word count (Tkn) lower by removing the excess key(phrase) word counts from the total:
Density = (Nkr / (Tkn -(Nkr * (Nwp-1)))) * 100.where Nwp = the number of terms in the keyphrase.