The problem of estimating the number of clusters k is considered one of the major challenges for partition clustering. The k-means algorithm is a division-based clustering method where only objects are entered into a set of K, and the algorithm decides the number group initially, but there is no specific way to estimate the best number for the cluster. The outcome of the clustering process can be better after being performed in more than one attempt. Therefore, the optimal count of iterations can be identified through a steady method in advance that can determine the time and number of rounds. So, the problem is finding the optimal number (k) in an easy and fast way. The aim of this paper is to use a genetic algorithm (GA) with a new objective function to determine the best number of clusters of different types of datasets. The fitness function optimizes both the heterogeneity among clusters and homogeneity within each cluster. Utilize the gap statistic equation, the optimal number of clusters is determined in four standard datasets.