In the field of precision measurement, subdividing displacement within the grating period to achieve high precision and high resolution remains a significant challenge. For subdivision, traditional optical linear encoders need complex coding and complicated optical systems, which struggle to meet the demands of nanometer measurement. In this paper, based on the fundamental principles of grating displacement measurement, a high-precision peak positioning method from grating images is proposed for linear displacement measurements with nanometer resolution and submicron accuracy. By utilizing a local gradient interpolation algorithm to optimize curves, it could further improve the accuracy of displacement measurement. Experiments demonstrate that this method achieves a resolution of 2 nm and an accuracy of ± 0.1 μm in a range of 50 mm using a grating with a 20 μm period. This sets the groundwork for subdividing optical linear encoders further, the resolution and accuracy could be further improved by optimizing the subdivision method.