In this study, the dynamic analysis of a beam is analyzed by using the finite element method when the beam has moving mass and axial load. To consider the contact force between the moving mass and beam, coupled nonlinear equations of contact dynamics are derived, and then the weak form for the finite element method is established. The finite element computer programs based on the Lagrange multiplier method are developed to compute the contact force. Furthermore, a variety of simulations are performed for various design parameters such as moving mass velocity, compressive axial load and tension load. Finally, relations between the dynamic response and contact force are also discussed.