Wireless sensor networks (WSNs) contain an inordinate number of sensor nodes that are spatially distributed. The network is composed of entities that determine its lifetime. The WSN nodes are equipped with a battery whose autonomy is limited in duration. In this paper, different solutions are introduced to improve the overall energy consumption of the network in order to improve its lifetime. Contrary to many works considering the clustering algorithm as one potential candidate to improve the network's lifetime, this study has investigated the firefly algorithm optimization where an optimal cluster head is selected from a group of nodes. The set-up process of the cluster head is based on a set of conditions. To measure the performance of the proposed approach, the number of dead nodes and data packets received by the base station (BS) or sink node are considered. The results are tested on 100 nodes for 5000 transmission rounds, the amount of data transported is 20 million bits a little more than the other methods. It has been shown that the proposed solution outperformed the traditional low energy adaptive clustering hierarchy (LEACH), threshold sensitive energy efficient sensor network (TEEN), and developed distributed energy-efficient clustering (DEEC) approaches.