The primary aim of Wireless Sensor Network (WSN) design is achieving maximum lifetime of network. Organizing sensor nodes into clusters achieves this goal. Further, the nodes which do not join any cluster consume high energy in transmitting data to the base station and should be avoided. There is a need to optimize the cluster formation process by preventing these left-out nodes. Bacterial Foraging Optimization (BFO) is one of the potential bio-inspired techniques, which is yet to be fully explored for its opportunities in WSN. Bacterial Foraging Algorithm for Optimization (BFAO) is used in this paper as an optimization method for improving the clustering performance in WSN by preventing left-out node’s formation. The performance of BFAO is compared with the Particle Swarm Optimization (PSO) and LEACH. The results show that the BFAO performance is better than PSO and LEACH in improving the lifetime of network and throughput. © Springer Nature Singapore Pte Ltd. 2020.