K-means clustering algorithms of wireless sensor networks are potential solutions that prolong the network lifetime. However, limitations hamper these algorithms, where they depend on a deterministic K-value and random centroids to cluster their networks. But, a bad choice of the K-value and centroid locations leads to unbalanced clusters, thus unbalanced energy consumption. This paper proposes X-means algorithm as a new clustering technique that overcomes K-means limitations; clusters constructed using tentative centroids called parents in an initial phase. After that, parent centroids split into a range of positions called children, and children compete in a recursive process to construct clusters. Results show that X-means outperformed the traditional K-means algorithm and optimized the energy consumption.