A magnetic sensor comprising a Hall device comprising: a p-type impurity region; and an n-type impurity region disposed on the p-type impurity region and serving as a magnetosensitive portion, wherein an n-type impurity concentration N (atoms/cm 3) and a distribution depth D (μm) of the n-type impurity region satisfy following relational expressions: N < 1.0 × 10 16 and N > 3.802 × 10 16 × D - 1.761, wherein the n-type impurity concentration N represents a maximum concentration of the n-type impurity concentration in the n-type impurity region and the distribution depth D represents a length in depth direction from a point at which the n-type impurity concentration is a maximum to a point at which the n-type impurity concentration is 1/10 of the n-type impurity concentration N, further comprising: a temperature characteristic storage unit storing information on the temperature characteristics of the Hall device; a correction signal generating unit generating a correction signal for correcting an output of the Hall device on the basis of an output of a temperature sensor and the information on the temperature characteristics of the Hall device; and a signal correcting unit receiving inputs of the correction signal generated by the correction signal generating unit and an output signal of the Hall device input and correcting the output signal of the Hall device on the basis of the correction signal. a p-type impurity region; and an n-type impurity region disposed on the p-type impurity region and serving as a magnetosensitive portion, wherein an n-type impurity concentration N (atoms/cm 3) and a distribution depth D (μm) of the n-type impurity region satisfy following relational expressions: N < 1.0 × 10 16 and N > 3.802 × 10 16 × D - 1.761, wherein the n-type impurity concentration N represents a maximum concentration of the n-type impurity concentration in the n-type impurity region and the distribution depth D represents a length in depth direction from a point at which the n-type impurity concentration is a maximum to a point at which the n-type impurity concentration is 1/10 of the n-type impurity concentration N, further comprising: a temperature characteristic storage unit storing information on the temperature characteristics of the Hall device; a correction signal generating unit generating a correction signal for correcting an output of the Hall device on the basis of an output of a temperature sensor and the information on the temperature characteristics of the Hall device; and a signal correcting unit receiving inputs of the correction signal generated by the correction signal generating unit and an output signal of the Hall device input and correcting the output signal of the Hall device on the basis of the correction signal. a temperature characteristic storage unit storing information on the temperature characteristics of the Hall device; a correction signal generating unit generating a correction signal for correcting an output of the Hall device on the basis of an output of a temperature sensor and the information on the temperature characteristics of the Hall device; and a signal correcting unit receiving inputs of the correction signal generated by the correction signal generating unit and an output signal of the Hall device input and correcting the output signal of the Hall device on the basis of the correction signal.