In a totally inelastic collision, both colliding partners remain connected after the collision. For simplicity, we only consider a central, inelastic collision in which both colliding partners move along one axis. In this case, the momentum balance can be written as follows:
\begin{equation}
p_1 + p_2 = p_1' + p_2'
\end{equation}
Substituting the definition of momentum yields:
\begin{equation}
m_1 v_1 + m_2v_2 = m_1v_1' + m_2v_2'
\end{equation}
If we now consider that both bodies stick together after the collision and therefore must have the same final velocity, i.e., $v_1' = v_2' = v'$, then by transforming the equation for $v$ we obtain the following formula for $v'$:
\begin{equation}
{v' = \frac{m_1 v_1 + m_2 v_2}{m_1 + m_2}}
\end{equation}
After the collision, both bodies continue to move at the velocity of their common center of mass.
We now consider the conservation of energy in this system in more detail. As in any physical system, the total energy must always be completely conserved. However, if we only consider the kinetic energy, we find that it is smaller after the collision than before. This can be shown by subtracting the kinetic energies before and after the collision:
\begin{equation}
\Delta E = E_\mathrm{kin} - E'_\mathrm{kin}
\end{equation}
This gives:
\begin{equation}
\Delta E = \frac{1}{2}m_1v_1^2 + \frac{1}{2}m_2v_2^2 - \frac{1}{2}(m_1+m_2)v'^2
\end{equation}
With this we obtain the difference in energies:
\begin{equation}
{\Delta E = \frac{1}{2}\frac{m_1\cdot m_2}{m_1 + m_2}(v_1-v_2)^2}
\end{equation}
In words, this relationship means: The greater the difference in speed between the two bodies before the collision, the greater the difference in kinetic energy before and after the collision. However, since energy cannot be lost, it is converted into deformation and heat energy of the two bodies. This can be observed particularly well in the deformed bodies of two cars after an inelastic collision. In the extreme case, both bodies have identical masses and the same velocities with opposite signs. In this case, both bodies are at rest after the collision because $v' = 0$ then holds, and all the energy is converted into deformation.