So here is the formular I am trying to understand:
Let G = (V,E) be a graph, with an adjacency matrix $A_G$. The number of cycles with a length of 4 in G is the result of the following calculation:
$$\frac{1}{8}\left(\operatorname{tr}(A^4_G)-2|E| -4\sum_{v\in V} \binom{\deg_G(v)}{2}\right)$$
What I do understand so far, is that the i'th entry of the trace of the adjacency matrix $A^4_G$ shows the number of walks of length 4 that start in $v_i$ and end in $v_i$. Since these aren't necessarily cycles, I have to subtract all walks of length 4, that aren't cycles. I therefore subtract two times the number of edges in G, i.e. (-2|E|), since each edge is connected to two vertices and each $v_i$ has a walk of length 4 that ends in $v_i$ through moving back and forth on the same edge. The walks of length 4 that I still need to subtract, are probably the ones of the form $v_i->v_j->v_i->v_x->v_i$, as they aren't cycles either. This is probably what $-4\displaystyle\sum_{v\in V} \binom{\deg_G(v)}{2}$ is for, but I can't seem to understand the logic behind it. Why does this formular succeed to sum up the number of walks of the form $v_i->v_j->v_i->v_x->v_i$ in the given graph? Also, why do I have to divide the end result by 8?
Your logic is basically sound. The count $4\displaystyle\sum_{v\in V} \binom{\deg_G(v)}{2}$ is actually responsible for removing two different types of walks: