There are 2 ways of calculating density.
The basic method consists of measuring the number of times a keyword appears on the page as a percentage of the total word count of that page. The complex method consists of measuring keyword density of the page plus the text components in meta tags: Title, Keywords, Alt Text, Description, and Comments. Most SEOs refer to the first method when talking about keyword density though. But, how do search engines measure keyword density? They actually use the complex method to measure it. I will explain later how to adjust to this.
Were should the keywords be used?
Diversify the density of your keywords in different areas of your page. Starting with the Title, and following with the beginning of the page, like in the headings, other sub-headings, and in the introductory paragraphs would certainly be of benefit. Every search engine algo is different, so you must choose an average keyword density that can make your site rank well in the top ten positions in the SERPs.
The importance of keyword density.
Keyword density can be very beneficial when done right, but it can also have a very negative influence when overdone. This is known as "keyword stuffing". When you stuff keywords in your page, this will be detected and your site will get penalized for doing so. This could go as far as getting your entire site blacklisted from a particular search engine, if you are found keyword stuffing too many times.
There is no secret keyword formula.
No matter what you may think, or read on forums or even articles by such “SEO Gurus”, there is no secret formula for keyword density. There are, however, certain guidelines that need to be followed, and they are available to the public form the search engines themselves. Keywords density is one of most critical elements in SEO, and if you can master it you get higher rankings for your site.
So what is the right keyword density?
Your keyword density must be right to improve your search engine ranking. The “ideal” keyword density will always help to achieve high rankings. But how much is too much? If too low, you will not get the maximum benefits, if too high your site might get flagged as spam… Ok, there is no “one number fits all” here, but based on real case studies, the average top ranking Google site averages basic 1.9% keyword density. I wouldn’t go over 2%. This is an average value, and I am talking about basic percentages here, not complex. But it translates well to their complex values.