The invention provides a speed reducer, a driving device and a rotary drilling rig, and relates to the technical field of rotary drilling rigs. The speed reducer comprises a shell and an input shaft,wherein the input shaft is arranged in the shell, the input end of the input shaft is provided with a connecting sleeve, the circumferential direction of the connecting sleeve is uniformly provided with protrusions or grooves, the position, corresponding to the connecting sleeve, of the shell is provided with a sensor, the sensing end of the sensor extends into the shell, and the sensing end senses the height difference change of the protrusions or the grooves to obtain the rotation speed of the input end. The driving device uses the speed reducer, and the rotary drilling rig uses the drivingdevice. According to the speed reducer, the driving device and the rotary drilling rig, the sensor is arranged on the shell of the speed reducer to measure the speed of the input shaft of the speed reducer, the sensor is no longer affected by temperature, and the problem of hydraulic oil leakage is avoided. In addition, the sensor is no longer affected by the temperature, the service life is prolonged, meanwhile, the maintenance cost is reduced, and then the construction efficiency is improved.