A shim is a device used to adjust the homogeneity of a magnetic field. Shims received their name from the purely mechanical shims used to adjust position and parallelity of the pole faces of an electromagnet. Coils used to adjust the homogeneity of a magnetic field by changing the current flowing through it were called "electrical current shims" because of their similar function.
In NMR and MRI, shimming is used prior to the operation of the magnet to eliminate inhomogeneities in its field. Initially, the magnetic field inside an NMR spectrometer or MRI scanner will be far from homogeneous compared with an "ideal" field of the device. This is a result of production tolerances and of the magnetic field of the environment. Iron constructions in walls and floor of the examination room become magnetized and disturb the field of the scanner. The probe and the sample or the patient become slightly magnetized when brought into the strong magnetic field and create additional inhomogeneous fields. The process of correcting for these inhomogeneities is called shimming the magnet, shimming the probe or shimming the sample, depending on the assumed source of the remaining inhomogeneity. Field homogeneity of the order of 1 ppm over a volume of several liters is needed in an MRI scanner. High-resolution NMR spectroscopy demands field homogeneity better than 1 ppb within a volume of a few milliliters. There are two types of shimming: active and passive. Active shimming uses coils with adjustable current. Passive shimming involves pieces of steel with good magnetic qualities. The steel pieces are placed near the permanent or superconducting magnet. They become magnetized and produce their own magnetic field. In both cases, the additional magnetic fields add to the overall magnetic field of the superconducting magnet in such a way as to increase the homogeneity of the total field. There are different ways to define inhomogeneity of a magnetic field in the center of the MR spectrometer. Currently, for medical MR scanners, the industry standard is to measure volume root mean square values of the field for the different volumes in the middle of the scanner.