Reading: Defect Density

What are various ways of calculating defect density?

The formula itself is simple: Density = Total Defects Found / Size

if we see defect density at granular level say Codesize of a particular functionality X in a application Y along with number of files, then we may draw some good observations like
Taking an example here:- Lets say we have an application ABC, which have three functionality/modules A, B and C.
Code files for A =10 and KLOC=5k
Code files for B =5 and KLOC=1k
Code files for C =1 and KLOC=25k
Bugs found in A=40, B=50, and C=5

Defect density = Total number of defects/LOC (lines of code)

Defect density = Total number of defects/Size of the project

Size of Project can be Function points, feature points, use cases, KLOC etc

Defect Density can be used to:

1) Predict the remaining defects when compared to the expected defect density,

2) Determine if the amount of testing is sufficient.

3) Establish a database of standard defect densities.

What are you going to do with the defect density information you collect?
Depending on what you want / expect to discover, you could pilot some different measurements on different parts of the code base and see which versions of the metric were most measurable.