diff --git a/codes/hf.py b/codes/hf.py
index aac48be3a475096d56ceeb54381f64dd4bd07014..4ea39fa94770daf2de2a98b193d4e46bdcc6994b 100644
--- a/codes/hf.py
+++ b/codes/hf.py
@@ -126,7 +126,7 @@ def total_energy(h, rho):
     total_energy : float
         System total energy computed as tr[h@rho].
     """
-    return np.sum(np.trace(h @ rho, axis1=-1, axis2=-2)).real
+    return np.sum(np.trace(h @ rho, axis1=-1, axis2=-2)).real / np.prod(rho.shape[:-2])
 
 def updated_matrices(mf_k, model):
     """