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

I hope you like the information!