Recently, several model-based control designs have been proposed for motion systems and computerized numerical control (CNC) machines to improve motion accuracy. However, in real applications, their performance is seriously degraded when significant disturbances or cutting forces are applied. In this paper, we derive straightforward design procedures for a generalstructured unknown input observer (UIO) which perfectly decouples the effect of the external disturbance from the state estimation. Furthermore, we derive the optimal UIO by minimizing the estimation errors for both the state and the disturbance via the Riccati equation. Experimental results show that the performance of all advanced motion controllers suffers when external loads are applied. By compensating for the disturbance of a servo motor using the proposed optimal-UIO, the original contouring accuracy, which is degraded by the external loading, can be successfully recovered.