The paper analyzed principle of ultrasonic ranging and its main error causes and put forward an error compensation algorithm of ultrasonic ranging based on BP neural network. The algorithm trains samples of given input vector and target vector, and adjusts weights and threshold in process of training constantly, so as to reach a mapping relationship to correct error. The simulation result verified effectiveness of the algorithm.