To address the challenge of local optimization and step size factor parameter setting in the full attraction model of the firefly algorithm (FA), this paper introduces level-based attraction and variable step size to FA. In the level-based attraction model, fireflies are firstly grouped in different levels according to the brightness, and each firefly randomly selects two fireflies from a higher level to learn from. By using the variable step size strategy, the searching step size decreases with the number of iterations. Herein, the level-based attracting model can increase the diversity of individual learning and improve the ability to jump out of local optimization. Meanwhile, dynamic adjustment of step size can balance the detection and development ability of the algorithm and improve the optimization accuracy of the algorithm. To evaluate the effectiveness of the proposed algorithm, comparisons are drawn against optimized FA, particle swarm optimization algorithm, artificial bee colony algorithm and differential evolution algorithm on a variety of test function sets. INDEX TERMS Firefly algorithm, full attraction model, level-based attracting model, variable step size.