An encoder for generating a position signal representative of a position of a grating surface relatively to the encoder based on a phase or phase difference of a combined radiation beam, the encoder comprising: an enclosing device having a receiving surface, a first medium and a second medium, wherein the receiving surface is arranged to receive from an ambient environment a first radiation beam and a second radiation beam which originate from the grating surface; and an optical component arranged to combine the first radiation beam and the second radiation beam into the combined radiation beam, wherein the enclosing device is arranged to propagate the first radiation beam along a first path and the second radiation beam along a second path, wherein the first path and the second path are from the receiving surface to the optical component, wherein the first path has a first path length and the second path has a second path length different from the first path length, wherein the enclosing device is arranged to isolate the first path and the second path from the ambient environment, wherein the first path is at least partly through the first medium, wherein the second path is at least partly through the second medium, wherein a path length of the first path through the second medium is different from a path length of the second path through the second medium, so as to make a total optical path length of the first radiation beam and a total optical path length of the second radiation beam equal to each other, wherein the total optical path length of the first radiation beam and the total optical path length of the second radiation beam are between a radiation source and a sensor for receiving the combined radiation beam. an enclosing device having a receiving surface, a first medium and a second medium, wherein the receiving surface is arranged to receive from an ambient environment a first radiation beam and a second radiation beam which originate from the grating surface; and an optical component arranged to combine the first radiation beam and the second radiation beam into the combined radiation beam, wherein the enclosing device is arranged to propagate the first radiation beam along a first path and the second radiation beam along a second path, wherein the first path and the second path are from the receiving surface to the optical component, wherein the first path has a first path length and the second path has a second path length different from the first path length, wherein the enclosing device is arranged to isolate the first path and the second path from the ambient environment, wherein the first path is at least partly through the first medium, wherein the second path is at least partly through the second medium, wherein a path length of the first path through the second medium is different from a path length of the second path through the second medium, so as to make a total optical path length of the first radiation beam and a total optical path length of the second radiation beam equal to each other, wherein the total optical path length of the first radiation beam and the total optical path length of the second radiation beam are between a radiation source and a sensor for receiving the combined radiation beam.