The spin of a field I have searched for an explanation for the math behind the spin of fields, such as the electromagnetic field has a spin of 1 and the gravitational field has a spin of 2.
The internet did not provide a satisfying helpful explanation.
I understand that it has to do with repulsion and attraction of different charges but I don't fully understand it.
Can someone explain the math to me, please?
 A: The math behind spin of fields can be better understood using 2-spinor formalism and Twistor theory. In 3+1 dim space-times, given a 4-vector $v^a$, we can associate a Hermitian matrix $V^{AA'}$ defined by $V^{AA'}=v^a\sigma_a=\begin{bmatrix} V^0+V^3 & V^1+iV^2\\
V^1-iV^2 & V^0-V^3 \end{bmatrix}$. Using this representation, we can show that every orthochronous Lorentz transformation of $v^a$ corresponds to two spin transformations of $V^{AA'}$ , one being negative of the other: $V^{AA'}\to {t^A}_BV^{BB'}{\bar{t}^{A'}}_{B'}$, where ${t^A}_B$ matrices are elements of $SL(2,C)$. This is related to the fact that $SL(2,C)$ forms a double-cover of the orthochronous Lorentz group. Now we can write $V^{AA'}=\alpha^A\bar{\alpha}^{A'}$, where $\alpha^A$ and $\bar{\alpha}^{A'}$ are complex 2dimensional vectors and are known as spinors. An isomorphism exist between tangent vector space and the spin space: $T_pM\cong_{iso} S\otimes S'$. So $v^a\in T_pM$,  $\alpha^A\in S^A$ and $\bar{\alpha}^{A'}\in S^{A'}$. The isomorphism is defined by the Infeld van der Warden symbols. In our example, the hermitian matrix $V^{AA'}=v^a\sigma_a= \alpha^A\bar{\alpha}^{A'}$, so the Infeld van der Warden symbols ${\sigma_a}^{AA'}$ are nothing but the Pauli matrices $\sigma^a$ (defined upto some normalization).
Using 2-spinor formalism we can express a skew symmetric tensor $F_{ab}$ (such as the Maxwell's fields) in terms of symmetric 2-spinor $\phi_{AB}$ : $F_{ab}=\phi_{AB}\epsilon_{A'B'}+c.c.$. (The epsilon matrix $\epsilon_{AB}$ is skew symmetric and is used to raise and lower spinor indices). Then the free Maxwell's equation $\nabla^aF_{ab}=0$ is equivalent to $\nabla^{AA'}\phi_{AB}=0$. Similarly, the vacuum Einstein's equation $\nabla^aC_{abcd}=0$ is equivalent to $\nabla^{AA'}\Psi_{ABCD}=0$.
A general spin-n/2 free massless field equation is given by: $$\nabla^{AA'}\phi_{ABC\cdots L}=0$$where $\phi_{ABCD}$ is symmetric in all n spinor indices $A,B,\cdots, L$
In classical relativistic dynamics, we can define heicity of massless particles using Pauli-Lubanski spin vector $W^a$. If we know the 4-momentum and 4-angular momentum of massless particle in COM frame, then the consistency of trajectory equation $P^aM_{ab}=0$ demands $W^a=sP^a$, where $s$ is the helicity. In a previous post Spin without quantum mechanics? , I have tried to explain the connection b/w helicity $s$ and spin-n/2 of massless fields $\phi_{ABC\cdots L}$, if we look at the representation of solution of the spinor field $\phi_{ABC\cdots L}$ in Twistor space (https://ncatlab.org/nlab/show/twistor+space). First we note that the solution for massless spinor field $\phi$ in Twistor space is given by Penrose-transform:
$$\phi_{ABC\cdots L}=\frac{1}{2\pi i}\int_K \alpha_A\alpha_B\cdots \alpha_Lf(\alpha_R, -i\alpha_Rx^{RR'})\alpha_Md\alpha^M$$ The correct relativistic transformation of spinor field $\phi$ demands that the twistor function $f(\alpha_R, -i\alpha_Rx^{RR'})=f(Z)$ should have a homogeneity of degree $-n-2$ in twistor coordinates $Z_{\alpha}=(\alpha_A, -i\alpha_Ax^{AA'})$. We can also write the helicity $s$ of massless particle in terms of twistor coordinates: $s=\frac{1}{2}Z^{\alpha}\bar{Z}_{\alpha}$.
Now if we consider quantization of Twistor space (i.e. we elevate the twistor coordinates $Z,\bar{Z}$ to twistor operators $\hat{Z}$ and $\hat{\bar{Z}}=-\frac{\partial}{\partial Z}$ satisfying the commutation relation $[Z^{\alpha},Z^{\beta}]=[\bar{Z}_{\alpha},\bar{Z}_{\beta}]=0$ and $[Z^{\alpha},\bar{Z}_{\beta}]=\delta^{\alpha}_{\beta}$), then we can identify spin operator $s\to \hat{S}:=\frac{1}{4}(Z^{\alpha}\bar{Z}_{\alpha}+\bar{Z}_{\alpha}Z^{\alpha})=\frac{1}{2}(Z^{\alpha}\bar{Z}_{\alpha}-2)$. Fact that twistor function $f(Z)$ is homogeneous of degree $-n-2$, we can write $Z^{\alpha}\bar{Z}_{\alpha}f(Z)=-Z^{\alpha}\frac{\partial}{\partial Z^{\alpha}}f(Z)=(n+2)f(Z)$. Thus $\hat{S}f(Z)=sf(Z)=\frac{n}{2}f(Z)$. This shows that after quantization of twistor space, the spin n/2 field $\phi$ has a helicity defined by $s=n/2$.
Thus for scalar field $\phi$ satisfying $\nabla^a\nabla_a\phi=0$, we have $n=0$ or helicity $s=0$. For Maxwell's field equation $\nabla^{AA'}\phi_{AB}=0$, $n=2$, so helicity $s=n/2=1$.  Similarly for gravitational field $\Psi_{ABCD}$, $n=4$ or $s=2$ and so on..
