Aiming at the tool position optimization in five -axis CNC complex surfaces machining, a method to optimize tool position based on analysis and compensation of non -linear error was presented. the tool position calculation method of flat round cutter was described. The non-linear error caused by the change of tool axis vector was analyzed. The non-linear error model was established to get the maximum non-linear error of Interpolation segment. The tool position that meets the machining accuracy was obtained by the detection and compensation calculation to the non -linear error. The method above was simulated by computer. The computer simulation result showed that the nonlinear error compensation for complex surface had influence on geometric accuracy in CNC machining.