A magnetic sensor of an embodiment includes: a magnetic field detector including a magnetic layer in which a length in a first direction is 10 times or more of a length in a second direction perpendicular to the first direction and a length in a third direction perpendicular to the first direction and the second direction is ½ or less of the length in the second direction; a first magnetic material member arranged along the first direction, and in which a length in the third direction is longer than the length in the third direction of the magnetic layer; a first nonmagnetic insulating layer arranged between the magnetic field detector and the first magnetic material member, and in which a length in the second direction is ½ or less of the length in the second direction of the magnetic layer; and a circuit supplying current to the magnetic layer.