In order to improve the accuracy, reliability and efficiency of computer numerical control (CNC) machine tools, first, according to the working principle of servo motor and related physical relations, the mathematical model of servo system is established. Moreover, the mathematical model is used to establish the three-closed loop simulation structure of servo. Then, according to the simulation structure, a parameter optimization algorithm of CNC machine tool servo system based on improved particle swarm optimization (PSO) algorithm is proposed. Compared with the previous PSO algorithm, the PSO algorithm used has two improvements. First, it introduces the nonlinear dynamic inertia weight coefficient, and constructs the functional relationship between accelerated factor and inertia weight. Second, it introduces the extreme perturbation operator to increase the search range of particles. Moreover, the improved PSO algorithm is used to optimize the scale factor parameters in the regulator. The experimental results show that the dynamic performance of CNC machine tool servo system has been improved to a certain extent. Compared with the Proportion Integration Differentiation (PID) parameters without tuning, the overshoot of the system is reduced and the robustness is improved. In addition, the tuning PID parameters are compared with those of crowd search algorithm (SOA), PSO and genetic algorithm (GA). The results show that the adjustment time to the stable error of the CNC machine tool servo system optimized by GA algorithm is longer than other algorithms, and the oscillation of the transition time is severer. The PID parameters of CNC machine tool servo system optimized by improved PSO algorithm are obviously better than those optimized by other algorithms. The system using this parameter has a short adjustment time and an overshoot of 0. Therefore, the performance of the improved PSO algorithm is better than SOA, PSO and GA algorithm. The proposed algorithm provides a new idea for intelligent algorithm to solve the control parameter optimization problem of CNC machine tools.