A new bender supermirror polarizer is used to polarize the cold neutron beam at the Fundamental Neutron Physics Beamline at the Spallation Neutron Source. We present the design of a compensation magnet that was built around the polarizer to minimize the polarizer fringe fields that could compromise the magnetic field requirements of the NPDGamma experiment for the field uniformity in the spin rotator and the field direction in the liquid hydrogen target located downstream from the polarizer. The entire magnetic field environment of the experiment has been analyzed using a finite-element model. Measurements of the magnetic field gradients and field direction have been carried out and the results are less than the upper limits required in the experiment. According to the results the compensated fields meet the stringent magnetic field requirements of the experiment defined by the systematic errors that have to be well below the statistical uncertainty of 10-8 in our main observable, the gamma asymmetry in neutron capture on hydrogen. We describe the design of the magnetic field, the construction of the compensation magnet, and we compare results of the field measurements with the results from the model.