According to one embodiment, a magnetic sensor includes first and second elements, first and second interconnects, a first circuit portion electrically connected to the first and second interconnects and a second circuit portion electrically connected to the first and second elements. The first circuit portion supplies a first alternating current to the first interconnect and supplies a second alternating current to the second interconnect. The second circuit portion supplies a first element current to the first element and supplies a second element current to the second element. At a first time, the first alternating current has a first alternating current orientation, and the second alternating current has a second alternating current orientation. At a second time, the first alternating current has an opposite orientation to the first alternating current orientation, and the second alternating current has an opposite orientation to the second alternating current orientation.