We propose a new algorithm for wavefront sensing based on binary intensity modulation. The algorithm is based on the fact that a wavefront can be expended with a series of orthogonal and binary functions, the Walsh series. We use a spatial light modulator (SLM) to produce different binary-intensity-modulation patterns which are the simple linear transformation of the Walsh series. The optical fields under different binary-intensity-modulation patterns are detected with a photodiode. The relationships between the incident wavefront modulated with the patterns and their optical fields are built to determinate the coefficients of the Walsh series. More detailed and strict relationship equations are established with the algorithm by adding new modulation patterns according to the properties of the Walsh functions. An exact value can be acquired by solving the equations. Finally, with the help of phase unwrapping and smoothing, the wavefront can be reconstructed. The advantage of the algorithm is providing an analytical solution for the coefficients of the Walsh series to reconstruct the wavefront. The simulation experiments are presented and the effectiveness of the algorithm is demonstrated.