Optimization of the volume/weight in the gear train is of great importance for industries and researchers. In this paper, using the particle swarm optimization algorithm, a general gear train is optimized. The main idea is to optimize the volume/weight of the gearbox in 3 directions. To this end, the optimization process based on the PSO algorithm occurs along the height, length, and width of the gearbox to achieve the smallest possible gearbox. The constraints are divided into three types named geometrical, design and control constraints. The optimization process is presented for two and three-stage gear trains and by choosing different values for the gear ratio, input power and hardness of gears. The practical graphs for the optimum value of the weight/volume and all necessary design parameters of gearbox such as the number of stages, position, modulus of gears, face width of gears, and diameter of shafts are also presented. The results are validated by comparing with the results reported in the previous publications.