Let $f:\mathbb R\rightarrow\mathbb R$ be an isometry. Let us first assume $f(0)=0$(otherwise, we can just take $g(x)=f(x)-f(0)$, note that $g$ is also an isometry).
Note that $f(1)=\pm 1$. Suppose $f(1)=1$. Let $x\in\mathbb R$. Therefore, $|f(x)|=|x|$ and $|f(x)-1|=|x-1|$. It is easy to conclude from here that $f(x)=x$. Similarly, if $f(1)=-1$ then we can conclude that $f(x)=-x$. Therefore, the only isometries are the functions $f(x)=\pm x+c$ where $c\in\mathbb R$.
Let $f:\mathbb R\rightarrow\mathbb R$ be an isometry. Let us first assume $f(0)=0$(otherwise, we can just take $g(x)=f(x)-f(0)$, note that $g$ is also an isometry). Note that $f(1)=\pm 1$. Suppose $f(1)=1$. Let $x\in\mathbb R$. Therefore, $|f(x)|=|x|$ and $|f(x)-1|=|x-1|$. It is easy to conclude from here that $f(x)=x$. Similarly, if $f(1)=-1$ then we can conclude that $f(x)=-x$. Therefore, the only isometries are the functions $f(x)=\pm x+c$ where $c\in\mathbb R$.