A semiconductor device comprising: a substrate comprising silicon carbide of a first conductivity type; a semiconductor layer of the first conductivity type that is formed on a first main surface of the substrate; an element formation region provided in a central part of the semiconductor layer in a plan view; a first semiconductor region of a second conductivity type different from the first conductivity type, having a first depth from an upper surface of the semiconductor layer and formed annularly in the semiconductor layer outside the element formation region in a plan view; and a second semiconductor region of either of the first conductivity type or containing an inert element, having a second depth from the upper surface of the semiconductor layer and formed annularly in the semiconductor layer between the first semiconductor region and the periphery of the semiconductor layer, apart from the first semiconductor region and apart from the periphery of the semiconductor layer in a plan view, wherein the second semiconductor region includes a first end surface facing the first semiconductor region, as well as a second end surface on the opposite side of the first end surface, and characterized in that when the first depth is d TM, the second depth is d NR, a thickness of the semiconductor layer is d Epi, a distance from the first end surface of the second semiconductor region to the second end surface thereof is L NR, and a distance from the first end surface of the second semiconductor region to the periphery of the semiconductor layer is |X NR |, these variables have the following relationship: d NR ≥ d TM X NR + d NR ≥ d Epi 0 < L NR < X NR a substrate comprising silicon carbide of a first conductivity type; a semiconductor layer of the first conductivity type that is formed on a first main surface of the substrate; an element formation region provided in a central part of the semiconductor layer in a plan view; a first semiconductor region of a second conductivity type different from the first conductivity type, having a first depth from an upper surface of the semiconductor layer and formed annularly in the semiconductor layer outside the element formation region in a plan view; and a second semiconductor region of either of the first conductivity type or containing an inert element, having a second depth from the upper surface of the semiconductor layer and formed annularly in the semiconductor layer between the first semiconductor region and the periphery of the semiconductor layer, apart from the first semiconductor region and apart from the periphery of the semiconductor layer in a plan view, wherein the second semiconductor region includes a first end surface facing the first semiconductor region, as well as a second end surface on the opposite side of the first end surface, and characterized in that when the first depth is d TM, the second depth is d NR, a thickness of the semiconductor layer is d Epi, a distance from the first end surface of the second semiconductor region to the second end surface thereof is L NR, and a distance from the first end surface of the second semiconductor region to the periphery of the semiconductor layer is |X NR |, these variables have the following relationship: d NR ≥ d TM X NR + d NR ≥ d Epi 0 < L NR < X NR