The above formula is true for any compression spring. Being one of most basic spring, the coil compression spring has undergone various tests and studies, which allowed to come up with a formula (based on experiments only and can be viewed as a rule of thumb - but has been regarded as highly accurate) that connect the major coil spring parameters between themselves:
k = (Gd4) / 8D3Na
In this formula:
k- is the spring constant
G – is the Sheer Modulus of the spring material
d – is the wire diameter
D – is the spring mean diameter (the average between OD (outer diameter) and ID (inner diameter)
Na – is the number of active coils. This number will change based on type of coil spring, varying between Nc (total number of coils) and Nc-2.

click to enlarge