An optical encoder comprising: an origin point detection scale having an origin point detection pattern and an inverse origin point detection pattern, which has the inverse arrangement of the origin point detection pattern in the length measurement direction; a light source configured to emit light toward the origin point detection scale (10, 40); a light source grid inserted on the light source side of the origin point detection scale, the light source grid having a first light source grid pattern; a photoreceiver configured to detect light from the origin point detection scale (10, 40); and a photoreceiver grid inserted on the photoreceiver side of the origin point detection scale (10, 40), the photoreceiver grid having a first photoreceiver grid pattern that is one of the following first and second alternatives: in the first alternative, a pattern identical to the first light source grid pattern; and in the second alternative, a pattern that is the inverse of the first light source grid pattern, wherein, in both first and second alternatives, each of the origin point detection pattern, the inverse origin point detection pattern, the first light source grid pattern, and the first photoreceiver grid pattern comprise: a reference grid pattern in which a light emission portion and a light blocking portion are repeatedly formed at a pitch P in a length measurement direction; and a plurality of grid patterns in which the light emission portion and the light blocking portion are repeatedly formed at a pitch that is equal to 2 n x P in the length measurement direction, where n is an integer of at least 1, the grid patterns provided at identical positions with respect to the reference grid pattern having equal pitch and the grid patterns provided at different positions with respect to the reference grid pattern having differing pitch; in either the origin point detection pattern or the first light source grid pattern, a boundary between the light emission portion and the light blocking portion is provided at a length measurement direction center of the reference grid pattern and the grid patterns, and in the other of the two patterns, the light emission portion and the light blocking portion are arranged such that a center of one of the light emission portion and the light blocking portion is positioned at the length measurement direction center of the reference grid pattern and grid patterns. an origin point detection scale having an origin point detection pattern and an inverse origin point detection pattern, which has the inverse arrangement of the origin point detection pattern in the length measurement direction; a light source configured to emit light toward the origin point detection scale (10, 40); a light source grid inserted on the light source side of the origin point detection scale, the light source grid having a first light source grid pattern; a photoreceiver configured to detect light from the origin point detection scale (10, 40); and a photoreceiver grid inserted on the photoreceiver side of the origin point detection scale (10, 40), the photoreceiver grid having a first photoreceiver grid pattern that is one of the following first and second alternatives: in the first alternative, a pattern identical to the first light source grid pattern; and in the second alternative, a pattern that is the inverse of the first light source grid pattern, wherein, in both first and second alternatives, in the first alternative, a pattern identical to the first light source grid pattern; and in the second alternative, a pattern that is the inverse of the first light source grid pattern, wherein, in both first and second alternatives, each of the origin point detection pattern, the inverse origin point detection pattern, the first light source grid pattern, and the first photoreceiver grid pattern comprise: a reference grid pattern in which a light emission portion and a light blocking portion are repeatedly formed at a pitch P in a length measurement direction; and a plurality of grid patterns in which the light emission portion and the light blocking portion are repeatedly formed at a pitch that is equal to 2 n x P in the length measurement direction, where n is an integer of at least 1, the grid patterns provided at identical positions with respect to the reference grid pattern having equal pitch and the grid patterns provided at different positions with respect to the reference grid pattern having differing pitch; a reference grid pattern in which a light emission portion and a light blocking portion are repeatedly formed at a pitch P in a length measurement direction; and a plurality of grid patterns in which the light emission portion and the light blocking portion are repeatedly formed at a pitch that is equal to 2 n x P in the length measurement direction, where n is an integer of at least 1, the grid patterns provided at identical positions with respect to the reference grid pattern having equal pitch and the grid patterns provided at different positions with respect to the reference grid pattern having differing pitch; in either the origin point detection pattern or the first light source grid pattern, a boundary between the light emission portion and the light blocking portion is provided at a length measurement direction center of the reference grid pattern and the grid patterns, and in the other of the two patterns, the light emission portion and the light blocking portion are arranged such that a center of one of the light emission portion and the light blocking portion is positioned at the length measurement direction center of the reference grid pattern and grid patterns.