We improve the bound of the
g
g
-invariant of the ring of integers of a totally real number field, where the
g
g
-invariant
g
(
r
)
g(r)
is the smallest number of squares of linear forms in
r
r
variables that is required to represent all the quadratic forms of rank
r
r
that are representable by the sum of squares. Specifically, we prove that the
g
O
K
(
r
)
g_{\mathcal {O}_K}(r)
of the ring of integers
O
K
\mathcal {O}_K
of a totally real number field
K
K
is at most
g
Z
(
[
K
:
Q
]
r
)
g_{\mathbb {Z}}([K:\mathbb {Q}]r)
. Moreover, it can also be bounded by
g
O
F
(
[
K
:
F
]
r
+
1
)
g_{\mathcal {O}_F}([K:F]r+1)
for any subfield
F
F
of
K
K
. This yields a subexponential upper bound for
g
(
r
)
g(r)
of each ring of integers (even if the class number is not
1
1
). Further, we obtain a more general inequality for the lattice version
G
(
r
)
G(r)
of the invariant and apply it to determine the value of
G
(
2
)
G(2)
for all but one real quadratic field.