An encoder comprising: a main scale having a first main signal pattern being periodic in a measurement axis direction and a first reference pattern for determination of a reference position in the measurement axis direction; a first sensor and a second sensor which are opposed to the main scale and are movable relative to the main scale in the measurement axis direction, the first sensor detecting a variation of the relative position of the first main signal pattern in the measurement axis direction, the second sensor detecting how close to it the first reference pattern is located; and a signal processor configured to output a signal indicating a movement length of the main scale on the basis of an output signal of the first sensor using, as a reference, a reference position that is determined on the basis of an output signal of the second sensor, characterised in that: the first reference pattern has a plurality of patterns (1081, 1082...) which are arranged in the measurement axis direction and have the same width in the measurement axis direction, the plurality of patterns (1081, 1082...) each being periodic in the measurement axis direction with respective different pitches, at least one of the plurality of patterns (1081, 1082...) being smaller in pitch than the first main signal pattern; the second sensor has a plurality of detection regions which are in one-to-one correspondence with the plurality of patterns (1081, 1082...) of the first reference pattern; and the signal processor comprises: an addition calculating section configured to calculate an addition signal (It) by adding up output signals of the plurality of detection regions of the second sensor; a square calculating section configured to calculate a squared signal (Is) by squaring the addition signal (It) at least once; and a judging section configured to output a reference signal for determination of a reference position according to signal levels of the squared signal (Is). a main scale having a first main signal pattern being periodic in a measurement axis direction and a first reference pattern for determination of a reference position in the measurement axis direction; a first sensor and a second sensor which are opposed to the main scale and are movable relative to the main scale in the measurement axis direction, the first sensor detecting a variation of the relative position of the first main signal pattern in the measurement axis direction, the second sensor detecting how close to it the first reference pattern is located; and a signal processor configured to output a signal indicating a movement length of the main scale on the basis of an output signal of the first sensor using, as a reference, a reference position that is determined on the basis of an output signal of the second sensor, characterised in that: the first reference pattern has a plurality of patterns (1081, 1082...) which are arranged in the measurement axis direction and have the same width in the measurement axis direction, the plurality of patterns (1081, 1082...) each being periodic in the measurement axis direction with respective different pitches, at least one of the plurality of patterns (1081, 1082...) being smaller in pitch than the first main signal pattern; the second sensor has a plurality of detection regions which are in one-to-one correspondence with the plurality of patterns (1081, 1082...) of the first reference pattern; and the first reference pattern has a plurality of patterns (1081, 1082...) which are arranged in the measurement axis direction and have the same width in the measurement axis direction, the plurality of patterns (1081, 1082...) each being periodic in the measurement axis direction with respective different pitches, at least one of the plurality of patterns (1081, 1082...) being smaller in pitch than the first main signal pattern; the second sensor has a plurality of detection regions which are in one-to-one correspondence with the plurality of patterns (1081, 1082...) of the first reference pattern; and an addition calculating section configured to calculate an addition signal (It) by adding up output signals of the plurality of detection regions of the second sensor; a square calculating section configured to calculate a squared signal (Is) by squaring the addition signal (It) at least once; and a judging section configured to output a reference signal for determination of a reference position according to signal levels of the squared signal (Is).