Suppose the 4D Euclidean gauge theory with group $G \simeq SU(n), \ n \geqslant 2$. The vacuum solution (i.e., the solution giving zero gauge connection $F = DA$) is given by $$ \tag 1 A_{i}(x) = g\partial_{i}g^{-1}, $$ where $g$ is the gauge group element. It is characterized by the integer $n$ belonging to the homotopic class of the homotopic group $\pi_{3}(G)$, and hence by the Maurer-Cartan invariant $$ n = \frac{1}{24\pi^{2}}\int\limits_{S^{3}}\text{tr}\big[l^{3}\big], \quad l = g\partial g^{-1} $$ However, often people write $$ \tag 2 n = \frac{1}{16\pi^{2}} \int \limits_{S^{4}} \text{tr}\big[F^{2}\big] = \frac{1}{24\pi^{2}} \int \limits_{H^{+}}dK = \frac{1}{24\pi^{2}}\int\limits_{S^{3}}\text{tr}\big[l^{3}\big], $$ where $H^{+}$ is an upper patch of the sphere $S^{4}$ (and $H^{-}$ is the lower one), and the sphere $S^{3}$ is given as $S^{3} = H^{+} \cap H^{-}$.
But I don't understand why $F^{2}$ isn't identically zero for $(1)$, and therefore don't understand $(2)$. Can You help me?
(1) only describes the behavior of the gauge field on the boundary of ${R}^4$, i.e., on $S^3$. (In quantum field theory, this equation arises when one is looking for Euclidean classical field configurations of finite action; the finiteness of the action requires the field to go to a pure gauge on the boundary of $R^4$.) In the bulk of $R^4$, the gauge field can have any value compatible with this boundary condition (only gauge fields that belong to the topological sector $n=0$ can have the form (1) also in the bulk).
Thus, there is no contradiction in (2), since $tr(F^2)\not=0$ in the bulk. The stated equalities follow from the fact that $tr(F^2)$ is a total derivative $\partial_\mu K^\mu$, whose in integral can be recast as an integral of $K$ on $S^3$.