# Question regarding the energy computation of the Ising-Spin Model

In most of the Monte-Carlo-Algorithms I studied, I found, at the place where they compute the energy, always a line of code, where they divided by four.

For example, this code-snippet is taken from here

def Energy(Q):
starting_energy=0
for i in range(len(Q)):
for j in range(len(Q)):
g=Q[i,j]
n_y=Q[(i+1)%num,j]+Q[i,(j+1)%num]+Q[(i-1)%num,j]+Q[i,(j-1)%num]
starting_energy+=g*-n_y
return starting_energy/4


Another example can be found here

def calcEnergy(config):
'''Energy of a given configuration'''
energy = 0
for i in range(len(config)):
for j in range(len(config)):
S = config[i,j]
nb = config[(i+1)%N, j] + config[i,(j+1)%N] + config[(i-1)%N, j] + config[i,(j-1)%N]
energy += -nb*S
return energy/4.


From my understanding, we want to compute the energy of a spin-configuration that includes the spin we are currently looking at plus its closest neighbors. So in sum that would make 5 ising-spins we are computing in this function.

So why is it correct to return return energy/4 instead of return energy/5?

nb = config[(i+1)%N, j] + config[i,(j+1)%N] + config[(i-1)%N, j] + config[i,(j-1)%N