<p>There is provided an optical encoder including: an optical scale having a light transmitting portion (9) and light non-transmitting portion (8) and applying input light (4) so that the output patter becomes an optical code; a light source unit, and a light reception unit. The light non-transmitting portion is set so that the incident angle of the optical axis (6) of the input light (4) from the light source (1) is not smaller than a critical angle and includes at least one set of inclined surfaces (8a, 8b) having a shape of inversed "V" spreading toward the incident side of the input light. The optical encoder is configured so that the incident light (4) incident to one of the inclined surfaces (8a) is totally reflected and comes onto the other inclined surface (8b) where at least a part of the light is reflected and the reflected light (10) reflected by the other inclined surface (8b) will not come to the light emitting portion of the light source (1) or a reflection portion (3) around the light emitting portion. With this configuration, it is possible to suppress an error caused by re-entering of the ray reflected from the light non-transmitting portion of the optical scale to another track or to its track.</p>