Reactive power compensation is one of the practical tools that can be used to improve power systems and reduce costs. These benefits are achieved when the compensators are installed in a suitable place with optimal capacity. This study solves the issues of optimal supply and the purchase of reactive power in the IEEE 30-bus power system, especially when considering voltage stability and reducing total generation and operational costs, including generation costs, reserves, and the installation of reactive power control devices. The modified version of the artificial bee colony (MABC) algorithm is proposed to solve optimization problems and its results are compared with the artificial bee colony (ABC) algorithm, the particle swarm optimization (PSO) algorithm and the genetic algorithm (GA). The simulation results showed that the minimum losses in the power system requires further costs for reactive power compensation. Also, optimization results proved that the proposed MABC algorithm has a lower active power loss, reactive power costs, a better voltage profile and greater stability than the other three algorithms.