This magnetic sensor comprises a substrate, a magnetoresistive-element group, and a magnet group. The substrate has a first surface and a second surface on the opposite side from said first surface. The magnetoresistive-element group includes a first magnetoresistive element and a second magnetoresistive element. The first magnetoresistive element and the second magnetoresistive element are laid out on the first surface of the substrate. The magnet group includes a first magnet that faces the first magnetoresistive element and a second magnet that faces the second magnetoresistive element.