A rotary encoder comprising a rotor (12; 112; 212; 312) and a rotor carrying means (15; 115; 215; 315) in the form of a bushing, and a stator (14; 114; 214; 314) and a stator carrying means (16; 116; 216; 316), wherein the rotor (12; 112; 212; 312) is fixed to the rotor carrying means (15; 115; 215; 315), and the stator (12; 112; 212; 312) is fixed to the stator carrying means (16; 116; 216; 316), wherein the rotor (12; 112; 212; 312) and the stator (14; 114; 214; 314) are arranged in the rotary encoder such that, when the rotary encoder is arranged on a machine comprising a shaft (30; 32) having a rotation axis: a rotation of the rotor (12; 112; 212; 312) in relation to the stator (14; 114; 214; 314) about the rotation axis of the shaft (30; 32) is allowed, a relative movement between the rotor (12; 112; 212; 312) and the stator (14; 114; 214; 314) along the rotation axis of the shaft (30; 32) is restricted to a predetermined distance, and a movement of the rotor (12; 112; 212; 312) in relation to the shaft (30; 32) along the rotation axis of the shaft (30; 32) is allowed, the rotor carrying means (15; 115; 215; 315) and the stator carrying means (16; 116; 216; 316) are further arranged such that, when the rotor carrying means (15; 115; 215; 315) is arranged on the shaft (30; 32) and the stator carrying means (16; 116; 216; 316) is arranged on the machine comprising the shaft (30; 32), a rotation of the rotor carrying means (15; 115; 215; 315) in relation to the stator carrying means (16; 116; 216; 316) about the rotation axis of the shaft (30; 32) is allowed, and a relative movement between the rotor carrying means (15; 115; 215; 315) and the stator carrying means (16; 116; 216; 316) along the rotation axis of the shaft (30; 32) is restricted to the predetermined distance, the rotor carrying means (15; 115; 215; 315) is further arranged such that, when arranged on the shaft (30; 32), a movement of the rotor carrying means (15; 115; 215; 315) in relation to the shaft (30; 32) along the rotation axis of the shaft (30; 32) is allowed. wherein the rotor (12; 112; 212; 312) is fixed to the rotor carrying means (15; 115; 215; 315), and the stator (12; 112; 212; 312) is fixed to the stator carrying means (16; 116; 216; 316), wherein the rotor (12; 112; 212; 312) and the stator (14; 114; 214; 314) are arranged in the rotary encoder such that, when the rotary encoder is arranged on a machine comprising a shaft (30; 32) having a rotation axis: a rotation of the rotor (12; 112; 212; 312) in relation to the stator (14; 114; 214; 314) about the rotation axis of the shaft (30; 32) is allowed, a relative movement between the rotor (12; 112; 212; 312) and the stator (14; 114; 214; 314) along the rotation axis of the shaft (30; 32) is restricted to a predetermined distance, and a movement of the rotor (12; 112; 212; 312) in relation to the shaft (30; 32) along the rotation axis of the shaft (30; 32) is allowed, the rotor carrying means (15; 115; 215; 315) and the stator carrying means (16; 116; 216; 316) are further arranged such that, when the rotor carrying means (15; 115; 215; 315) is arranged on the shaft (30; 32) and the stator carrying means (16; 116; 216; 316) is arranged on the machine comprising the shaft (30; 32), a rotation of the rotor carrying means (15; 115; 215; 315) in relation to the stator carrying means (16; 116; 216; 316) about the rotation axis of the shaft (30; 32) is allowed, and a relative movement between the rotor carrying means (15; 115; 215; 315) and the stator carrying means (16; 116; 216; 316) along the rotation axis of the shaft (30; 32) is restricted to the predetermined distance, the rotor carrying means (15; 115; 215; 315) is further arranged such that, when arranged on the shaft (30; 32), a movement of the rotor carrying means (15; 115; 215; 315) in relation to the shaft (30; 32) along the rotation axis of the shaft (30; 32) is allowed. a rotation of the rotor (12; 112; 212; 312) in relation to the stator (14; 114; 214; 314) about the rotation axis of the shaft (30; 32) is allowed, a relative movement between the rotor (12; 112; 212; 312) and the stator (14; 114; 214; 314) along the rotation axis of the shaft (30; 32) is restricted to a predetermined distance, and a movement of the rotor (12; 112; 212; 312) in relation to the shaft (30; 32) along the rotation axis of the shaft (30; 32) is allowed, the rotor carrying means (15; 115; 215; 315) and the stator carrying means (16; 116; 216; 316) are further arranged such that, when the rotor carrying means (15; 115; 215; 315) is arranged on the shaft (30; 32) and the stator carrying means (16; 116; 216; 316) is arranged on the machine comprising the shaft (30; 32), a rotation of the rotor carrying means (15; 115; 215; 315) in relation to the stator carrying means (16; 116; 216; 316) about the rotation axis of the shaft (30; 32) is allowed, and a relative movement between the rotor carrying means (15; 115; 215; 315) and the stator carrying means (16; 116; 216; 316) along the rotation axis of the shaft (30; 32) is restricted to the predetermined distance, the rotor carrying means (15; 115; 215; 315) is further arranged such that, when arranged on the shaft (30; 32), a movement of the rotor carrying means (15; 115; 215; 315) in relation to the shaft (30; 32) along the rotation axis of the shaft (30; 32) is allowed.