We have studied the influence of an externally applied magnetic field on the photon and dark count rates of meander-type niobium nitride superconducting nanowire single-photon detectors. Measurements have been performed at a temperature of 4.2 K, and magnetic fields up to 250 mT have been applied perpendicularly to the meander plane. While photon count rates are field independent at weak applied fields, they show a strong dependence at fields starting from approximately ±25 mT. This behavior, as well as the magnetic field dependence of the dark count rates, is in good agreement with the recent theoretical model of vortex-assisted photon detection and spontaneous vortex crossing in narrow superconducting lines. However, the local reduction of the superconducting free energy due to photon absorption, which is the fitting parameter in the model, increases much slower with the photon energy than the model predicts. Furthermore, changes in the free-energy during photon counts and dark counts depend differently on the current that flows through the meander. This indicates that photon counts and dark counts occur in different parts of the meander.