Handwritten digit recognition is one of the most classical applications in the field of pattern recognition and has high commercial value. KNN algorithm is a non‐parametric statistical method mainly used to solve classification and regression problems. It is sensitive to training data and has high computational complexity. Aiming at the problem that traditional KNN algorithm is slow to recognize handwritten numbers, an improved KNN algorithm is proposed. PCA method is used to reduce the dimension of the data, which effectively reduces the time and space complexity of the traditional KNN algorithm in the distance calculation process, and filters out part of the noise in the data. The algorithm is verified on MNIST data set, and the results show that the recognition speed is significantly improved, and the recognition accuracy is improved to a certain extent.