From the TeXbook, second doubly dangerous paragraph on page 150:
Question: What happens if a subscript or superscript follows a large delimiter? Answer: That's a good question. After a \left delimiter, it is the first subscript or superscript of the enclosed subformula, so it is effectively preceded by {}. After a \right delimiter, it is a subscript or superscript of the entire \left...\right subformula. And after a \bigl or \bigr or \bigm or \big delimiter, it applies only to that particular delimiter. Thus, ‘\bigl(_2|’ works quite differently from ‘\left(_2|’.
From the manual of ε-TeX:
\left⟨delim⟩⟨math mode material⟩...\middle⟨delim⟩⟨math mode material⟩...\right⟨delim⟩
(generalizing TeX’s \left⟨delim⟩⟨math mode material⟩\right⟨delim⟩). For each ⟨math mode material⟩ ε-TeX begins a new group, starting out with a new math list (always in the same style) that begins with a left boundary item containing everything processed so far. This group must be terminated with either \middle or \right, at which time the internal math list is completed with a new boundary item containing the new delimiter. In the case of \middle, a new group is started again, in the case of \right, ε-TeX appends an Inner atom to the current list; the nucleus of this atom contains the internal math list just completed.
From these descriptions, it is clear that \middle is actually implemented the same as \left (with some tweaks). Subscripts and superscripts are legal after \right⟨delim⟩, because they apply to the whole subformula and, in the case of \middle, the subformula has not yet been formed.
For your problem, the solution is not using \left and \right, but switching to \biggl and \biggr:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
This is the formula with Barbara's suggestion
\[
N = \left( \frac{s\vphantom{d}}{2} \right)^2 - \left( \frac{d}{2} \right)^2
\]
and here it is with the proper sizes
\[
N = \biggl( \frac{s}{2} \biggr)^{\!2} - \biggl( \frac{d}{2} \biggr)^{\!2}
\]
with a small enhancement too.
\end{document}

\vphantom{d}in the numerator of the first fraction to make it the same height as the second. (comment rather than answer, since i'm sure this has been answered before. i'll look for it.) – barbara beeton Jun 28 '16 at 15:07\middleat all? These cases are much better treated with\bigand friends. – egreg Jun 28 '16 at 15:14\middle)^2not output the superscript in the correct position. – Manuel Jun 28 '16 at 15:15\left– egreg Jun 28 '16 at 15:15\left(^2not put the superscript in the correct position depending of the glyph? – Manuel Jun 28 '16 at 15:16\leftdoesn't accept a superscript or subscript field. Ask D. E. Knuth why.;-)– egreg Jun 28 '16 at 15:17\right<delim>. – egreg Jun 28 '16 at 15:27\bigbecause it's a trial and error solution, I'd prefer something more automatic – Lorenzo Cameroni Jun 28 '16 at 15:29\leftand\rightas much as you can. – egreg Jun 28 '16 at 15:45