There are various guidelines when picking the number of bins, where k is the number of bins and n is the range. The number of bins, k, can be calculated from a suggested bin width h as follows:
h = ,
where the braces indicate the ceiling function.
Square-root choice: The simplest method of deciding on the number of bins is to take square root of the number of data points.
k =
Sturges' formula: Sturges' Formula is derived from a binomial distribution and assumes that the data is normally distributed. Sturges' formula has been known to perform poorly in some cases if n is less than 30 and if the data is not normally distributed.
k =
Scott's normal reference rule: Scott's normal reference rule minimizes the integrated mean squared error of the density estimate and is well suited for random samples of normally distributed data.
h = ,
where is the sample standard deviation.
Freedman-Diaconis' choice: The Freedman-Diaconis' choice is based on the interquartile range (IQR). It is less sensitive to outliers in data than Scott's normal reference rule because of using the interquartile range.
h =