A rotary encoder of an incremental type, comprising: a rotation detector that outputs a continuous wave signal of a first phase and a continuous wave signal of a second phase according to rotation of a rotating body, the continuous signal of the first phase and the continuous signal of the second phase having a phase difference from each other; a signal output unit that generates a rectangular wave output signal of the first phase and a rectangular wave output signal of the second phase from the continuous wave signal of the first phase and the continuous wave signal of the second phase, respectively and outputs the rectangular wave output signals of the first phase and the second phase from the rotary encoder; an internal signal generator that generates a rectangular wave internal signal of the first phase and a rectangular wave internal signal of the second phase from the continuous wave signal of the first phase and the continuous wave signal of the second phase, respectively; a first counter that sets a count value in response to a pulse edge of the rectangular wave internal signal of the first phase and resets the count value in response to a pulse edge of the rectangular wave output signal of the second phase; a second counter that sets a count value in response to a pulse edge of the rectangular wave internal signal of the second phase and resets the count value in response to a pulse edge of the rectangular wave output signal of the first phase; and an abnormality detector that detects an abnormality of the rotary encoder when the count value of at least one of the first and second counters (46, 47) reaches a prescribed value. a rotation detector that outputs a continuous wave signal of a first phase and a continuous wave signal of a second phase according to rotation of a rotating body, the continuous signal of the first phase and the continuous signal of the second phase having a phase difference from each other; a signal output unit that generates a rectangular wave output signal of the first phase and a rectangular wave output signal of the second phase from the continuous wave signal of the first phase and the continuous wave signal of the second phase, respectively and outputs the rectangular wave output signals of the first phase and the second phase from the rotary encoder; an internal signal generator that generates a rectangular wave internal signal of the first phase and a rectangular wave internal signal of the second phase from the continuous wave signal of the first phase and the continuous wave signal of the second phase, respectively; a first counter that sets a count value in response to a pulse edge of the rectangular wave internal signal of the first phase and resets the count value in response to a pulse edge of the rectangular wave output signal of the second phase; a second counter that sets a count value in response to a pulse edge of the rectangular wave internal signal of the second phase and resets the count value in response to a pulse edge of the rectangular wave output signal of the first phase; and an abnormality detector that detects an abnormality of the rotary encoder when the count value of at least one of the first and second counters (46, 47) reaches a prescribed value.