Investigating the new physical response law of rock failure process will advance rock mass monitoring and early warning technology. This study conducted magnetic field monitoring experiments on sandstone deformation and failure under uniaxial loading and cyclic loading and unloading using fluxgate weak magnetic detection technology. The magnetic field signals during sandstone deformation and failure were tested, and the relationships between the magnetic field, load and acoustic emission were analyzed. The results indicate that sandstone generates magnetic field signals during deformation and failure. During uniaxial loading, as the load increases, the magnetic field signal in the compaction stage fluctuates and rises, with a high fluctuation coefficient. In the elastic stage, the magnetic field signal increases steadily while the fluctuation coefficient decreases. In the plastic stage, the magnetic field signal increases significantly, and the fluctuation coefficient increases in the late plastic stage. In the failure stage, the magnetic field signal rapidly increases, and the fluctuation coefficient changes significantly, corresponding to the load drop and the main failure. Compared to the fluctuation coefficient, the variance of the magnetic field signal remains relatively stable during the first three loading stages, but the variance gradually increases during the failure stage, showing a significant mutation. During cyclic loading and unloading, the magnetic field signal gradually increases with increasing load and decreases with reducing load. Near instability and failure, the magnetic field signal increases rapidly, which is significantly higher than the previous cyclic loading and unloading process. There is a strong correlation between the magnetic field signal and the acoustic emission count, indicating that the generation of the magnetic field is closely related to the deformation and failure of the sample. Under stress, micro-damage continuously forms inside sandstone, leading to non-uniform deformation between adjacent particles. This disrupts the electrical balance at the interface, resulting in the generation and migration of free charges that alter the current. The movement of charges and changes in current produce magnetic field signals. Evaluating rock mass stability using magnetic field signals is expected to be a new non-destructive, non-contact and continuous monitoring method.