For compensation of a magnetic field in an operating region a number of magnetic field sensors (S1, S2) and an arrangement of compensation coils (Hh) surrounding said operating region is used. The magnetic field is measured by at least two sensors (S1, S2) located at different positions outside the operating region, preferably at opposing positions with respect to a symmetry axis of the operating region, generating respective sensor signals (s1, s2), the sensor signals of said sensors are superposed to a feedback signal (ms, fs), which is converted by a controlling means to a driving signal (d1), and the driving signal is used to steer at least one compensation coil (Hh). To further enhance the compensation, the driving signal is also used to derive an additional input signal (cs) for the superposing step to generate the feedback signal (fs).