To find the magnetic field energy we recall that the flux varies linearly with current. Thus, when the flux is $\Phi$ for current $i$, we can write $\phi=A i$. The total energy inclosed in the field, when the current is $I$, is
$$
\begin{aligned}
W &=\int \xi i d t=\int N \frac{d \Phi}{d t} i d t \\
&=\int N d \Phi i=\int_{0}^{I} N A i d i=\frac{1}{2} N A I^{2}=\frac{1}{2} N \Phi I
\end{aligned}
$$
The characteristic factor $\frac{1}{2}$ appears in this way.