5. Let the sequence of natural numbers from $1 \sim 8$ be $a_{1}, a_{2}$, $\cdots, a_{8}$. Then
$$
\begin{array}{l}
\left|a_{1}-a_{2}\right|+\left|a_{2}-a_{3}\right|+\left|a_{3}-a_{4}\right|+\left|a_{4}-a_{5}\right|^{\prime}+ \\
\left|a_{5}-a_{6}\right|+\left|a_{6}-a_{7}\right|+\left|a_{7}-a_{8}\right|+\left|a_{8}-a_{1}\right|^{\prime}
\end{array}
$$

The maximum value is $\qquad$
5. 32 .

From the problem, we have
$$
\begin{aligned}
S= & \left|a_{1}-a_{2}\right|+\left|a_{2}-a_{3}\right|+\left|a_{3}-a_{4}\right|+ \\
& \left|a_{4}-a_{5}\right|+\left|a_{5}-a_{6}\right|+\left|a_{6}-a_{7}\right|+ \\
& \left|a_{7}-a_{8}\right|+\left|a_{8}-a_{1}\right| .
\end{aligned}
$$

Removing the absolute value signs in any term of this sum, we get one positive and one negative natural number. To achieve the maximum possible value of the sum, we need to take the numbers from 1 to 4 as negative and the numbers from 5 to 8 as positive. Thus,
$$
\begin{array}{l}
S=2[(8+7+6+5)-(4+3+2+1)]=32 \text {. } \\
\text { For example, }|8-4|+|4-7|+|7-1|+|1-5|+ \\
|5-2|+|2-6|+|6-3|+|3-8| \\
=32 .
\end{array}
$$