The invention discloses a method for automatically designing and optimizing a railway vertical profile. The method comprises the steps of carrying out ground line smoothening processing to an original ground line, fitting an initial slope to the smoothened ground line, carrying out vertical profile design constraint condition processing to the initial slope, forming a vertical profile automatic slope design scheme, optimizing the vertical profile based on a differential evolution algorithm, setting optimization control parameters, initializing the populations according to the vertical profile automatic slope design scheme, using a target function to assess the advantages and disadvantages of the individual vertical profile scheme, calculating an individual target function value, carrying out evolution among the populations by using a mutation operation, an interlace operation, a restoring operation, setting of railway tunnel and a selecting operation until the final evolution condition is reached, and outputting a vertical profile diagram and a standard check table. The method for automatically designing and optimizing railway vertical profile has the advantages of high automation degree, strong practicality, fast computing speed, and high promotion and application value in design and optimization of the railway vertical profile.