A reasonable estimate for the total internal heat of the Earth is $Q_E\sim 2 \times 10^{31}\,\mathrm{J}$ (see below).
The value most often found online, however, is "$12.6 \times 10^{24}\,\mathrm{MJ}$" (=$1.26 \times 10^{31}\,\mathrm{J}$). This can be traced back to the estimate of $3 \times 10^{27}\,\mathrm{kgcal}$ given in Chapter 4 of Armstead's 1983 text on Geothermal Energy. (Given that the precision of the source is only 1 significant figure ("3"), the value would be better reported as $\sim 1.3 \times 10^{31}\,\mathrm{J}$ or $\sim 1 \times 10^{31}\,\mathrm{J}$.)
Unfortunately, Armstead gives neither the calculation underlying this estimate nor cites a source.
This value is consistent with a quick Fermi estimate that the Earth's total internal heat is
$$Q_E \sim T_E\,M_E\,c_E \sim 2 \times 10^{31}\,\mathrm{J}$$
where $T_E\sim 3000\,\mathrm{K}$ and $c_E\sim 1000\,\mathrm{J/(kg\,K)}$ are plausible guesses for the average internal temperature and average specific heat capacity of the Earth's interior, and $M_E$ is the Earth's mass.
A consistent estimate of $2 \times 10^{31}\,\mathrm{J}$ can be found on page 376 and Table 4.1 of Detlev Möller's "Chemistry of the Climate System - Vol. 2: History, Change and Sustainability, 3rd Ed (2020)." (A version from an earlier edition can be found in the answer to another question.) This breaks down the calculation layer by layer within the Earth, but the heat content of the individual layers seem inconsistent, so I have recalculated a similar table below:
| Region |
Depth |
T |
Density |
Mass |
Matter |
Specific Heat |
Heat |
|
(km) |
(km) |
(°C) |
($g/cm^3$) |
(kg) |
(J/kg/K) |
(J) |
| crust |
0-30 |
~350 |
~3 |
4.6$\times10^{22}$ |
rocks |
1000 |
1.6$\times10^{28}$ |
| outer mantle |
30-300 |
~2000 |
~3.5 |
4.6$\times10^{23}$ |
rocks |
1100 |
1.0$\times10^{30}$ |
| inner mantle |
300-2890 |
~3000 |
~4.7 |
3.6$\times10^{24}$ |
rocks |
1100 |
1.2$\times10^{31}$ |
| outer core |
2890-5150 |
~5000 |
~10.5 |
1.8$\times10^{24}$ |
Fe-Ni |
800 |
7.1$\times10^{30}$ |
| inner core |
5150-6371 |
~6000 |
~12.5 |
$\times10^{22}$ |
Fe |
800 |
4.6$\times10^{29}$ |
| Total |
|
|
|
6.0$\times10^{24}$ |
|
|
2.0$\times10^{31}$ |
I used eyeball averages of the geothermal gradient and Preliminary Earth Reference Model (PREM) density profile. One can find different values for these and the specific heats, but nothing that changes the total heat value significantly.