A rotary encoder comprising: a rotary disk with an angle code; a light source for irradiating the angle code; a detector disposed on the side opposite to the light source with respect to the rotary disk for reading the angle code; and a processing unit for acquiring a reading value f(θ) based on the angle code read by the detector, wherein the light source includes a plurality of light-emitting elements, wherein a first light-emitting element is disposed at a position corresponding to an angle θ of the rotation, wherein a second light-emitting element is disposed at a known predetermined distance x L away from the first light-emitting element in a direction orthogonal to the diameter of the rotary disk, and wherein every time the rotary disk is rotated by a predetermined angle, where a rotation angle of the rotary disk is provided as θ and an arbitrary angle from the rotation angle θ within a reading range on the detector is provided as φ, the processing unit is configured to acquire a reading value f I (θ) at a reading position A CI on the detector corresponding to the angle θ, a reading value f I (θ+φ) at a reading position B CI on the detector corresponding to an angle θ+φ, and distance X CI between the reading positions A CI and B CI in the case of using the first light-emitting element and a reading value f II (θ+φ) at a reading position B CII on the detector corresponding to the angle θ+φ and distance X CII between the reading positions A CI and B CII in the case of using the second light-emitting element, to calculate a reading value error Δφ I due to deflection at the angle θ+φ in accordance with the following formula: Δφ I = x CI / x CII − x CI − x L * h θ + φ (wherein h(θ+φ) represents a difference between the reading value f II (θ+φ) and the reading value f I (θ+φ)), to obtain a difference g I (θ,φ) between an angle reading value taking an influence of an error into consideration obtained by f I (θ+φ)-Δφ I and the reading value f I (θ), and to self-calibrate the reading value f I (θ) based on a change in the difference g I (θ,φ). a rotary disk with an angle code; a light source for irradiating the angle code; a detector disposed on the side opposite to the light source with respect to the rotary disk for reading the angle code; and a processing unit for acquiring a reading value f(θ) based on the angle code read by the detector, wherein the light source includes a plurality of light-emitting elements, wherein a first light-emitting element is disposed at a position corresponding to an angle θ of the rotation, wherein a second light-emitting element is disposed at a known predetermined distance x L away from the first light-emitting element in a direction orthogonal to the diameter of the rotary disk, and wherein every time the rotary disk is rotated by a predetermined angle, where a rotation angle of the rotary disk is provided as θ and an arbitrary angle from the rotation angle θ within a reading range on the detector is provided as φ, the processing unit is configured to acquire a reading value f I (θ) at a reading position A CI on the detector corresponding to the angle θ, a reading value f I (θ+φ) at a reading position B CI on the detector corresponding to an angle θ+φ, and distance X CI between the reading positions A CI and B CI in the case of using the first light-emitting element and a reading value f II (θ+φ) at a reading position B CII on the detector corresponding to the angle θ+φ and distance X CII between the reading positions A CI and B CII in the case of using the second light-emitting element, to calculate a reading value error Δφ I due to deflection at the angle θ+φ in accordance with the following formula: Δφ I = x CI / x CII − x CI − x L * h θ + φ (wherein h(θ+φ) represents a difference between the reading value f II (θ+φ) and the reading value f I (θ+φ)), to obtain a difference g I (θ,φ) between an angle reading value taking an influence of an error into consideration obtained by f I (θ+φ)-Δφ I and the reading value f I (θ), and to self-calibrate the reading value f I (θ) based on a change in the difference g I (θ,φ).