Here's an exact formula:
For any positive integer $n,$ let $T(n)$ be the total number of bits that get flipped as one counts from $1$ to $n.$ Then $T(n)= 2n - \text{(the number of }1\text{'s in the binary representation of }n)-1.$ It's easy to prove this by induction:
Basis:
$T(1)= 0 = 2 \cdot 1 - 1- 1.$
Induction Step:
For convenience, write $B(n)$ for the number of $1$'s in the binary representation of $n.$
Assume that $T(n)= 2n - B(n)-1.$ We need to show that $T(n+1)= 2n+2 - B(n+1)-1.$
If the binary representation of $n$ ends with exactly $k \; 1$'s, then we can write $n$ in binary as $a_1 \dots a_j 0 1 1 1 \dots 1$ (with $k \; 1$'s at the end). (Note that $k$ may be $0,$ but that's OK.) So $n+1$ in binary is $a_1 \dots a_j 1 0 0 0 \dots 0$ (with $k \; 0$'s at the end). Looking at the number of $1$'s in each of these, you can see that $B(n+1)=B(n)-k+1$ (because there are $k \; 1$'s in $n$ that are lost in moving to $n+1,$ but there is one $0$ in $n$ that becomes a $1$ in $n+1$).
We need to flip $k+1$ bits to count from $n$ to $n+1,$ so \begin{align}T(n+1)&=T(n)+k+1 \\\\&=(2n - B(n)-1)+k+1 \\\\&=2n - B(n+1) + 1 \\\\&=2n+2 - B(n+1)-1,\end{align} as desired, completing the proof by induction.
So now we know that for every positive integer $n,$ $T(n)= 2n - \text{(the number of }1\text{'s in the binary representation of }n)-1.$
Since $T(n) < 2n$ for all positive integers $n,$ we have $T(n)=O(n).$ To see that this is the best possible estimate of that sort, observe that $B(n)$ is at most $\lfloor \log_2(n)\rfloor+1,$ the total number of bits in the binary representation of $n.$ So \begin{align} T(n) &= 2n-B(n)-2 \\\\& \ge 2n-\lfloor \log_2(n)\rfloor-3. \end{align}
Incidentally, it's probably worth mentioning that this isn't what is usually called linear running time, because that refers to a running time that is $O(n)$ where $n$ is the number of bits in the input. In this problem, $n$ is value of the input, not its size. If we measure running time in the usual way, based on the size of the input, then counting from $1$ to $n$ takes exponential running time (exponential in the number of bits in the binary number $n).$