The Shack-Hartmann wavefront sensor is composed of a lenslet array generating the spot images from which local slope is calculated and overall wavefront is measured. Generally the principle of wavefront reconstruction is that the spot centroid of each lenslet array is calculated from pixel intensity values in its subaperture and then overall wavefront is reconstructed by local slope of wavefront obtained by deviations from reference positions. Hence the spot image of each lenslet array has to remain in its subaperture for exact measurement of wavefront. However the spot of each lenslet array deviates from its subaperture area when wavefront with large local slopes enters the Shack-Hartmann sensor. In this research, we propose the spot image searching method that finds area of each measured spot image flexibly and determine the centroid of each spot in its area. Also the algorithms that match these centroids to their reference points unequivocally even if some of them are situated off the allocated subaperture are proposed. Finally we verify the proposed algorithm with the test of a defocus measurement through experimental setup for the Shack-Hartmann wavefront sensor. It has been shown that the proposed algorithm can expand the dynamic range without additional devices.