In the present paper, the exact modeling and frequency analysis of the mass sensor nanobeam are investigated based on a higher-order elasticity theory with taking into account the longitudinal discontinuity. The energy equations of the beam are expressed considering discontinuity, and finally, the vibration equations and boundary conditions of the non-uniform nanobeam are derived using Hamilton’s principle. By the implementation of an analytical solution, the number of shape functions equal to longitudinal discontinuities is assumed. Then, by expressing the compatibility and boundary conditions, the frequency equation of the discontinuous nanobeam is obtained and solved. Effects of different parameters such as sensed mass and size effects on the frequency behavior of the nanobeam are investigated at various vibrational modes. The results show that accurate modeling of discontinuous nanobeam is important. Also, Changing the position of the sensed mass to the free end of the nanotube increases the sensing feature of the beam, and the size effect reduces it. The size effect reduces the frequency and increases the amplitude of the mode shape, especially at higher vibrational modes. The results also show that the sensing feature of the mass sensor nanobeam is more prominent at higher modes of vibration, and therefore the use of mass sensor nanobeam at higher vibrational modes is recommended.