# Why is work done in a spring positive?

We know that a stretched spring obeys Hooke's law, such that $$F=-kx$$.

We can find the potential energy of stretching/compressing this spring by $$x$$, given by :

$$U_x-U_0=-\int_0^x F.dx = \frac{1}{2}kx^2$$

Setting $$U_0=0$$ as reference, we have $$U_x=\frac{1}{2}kx^2$$

However, this is also sometimes described as the work done by the spring.

Shouldn't the work done $$W$$ be given by $$\int F.dr$$, such that $$W=-\Delta U = -\frac{1}{2}kx^2$$ in this case ?

Isn't the work done by the spring negative ?

Also, in this case the potential energy comes to be negative.. In general, can we set any point as reference and set it to be $$0$$ and perform the integral between any two limits, to get either a positive or a negative $$U$$ ?

For example, in forces of the nature $$r^{-n} ,(n>1)$$ we usually take the reference at $$r=\infty$$ and integrate from $$\infty$$ to some point $$r$$. In case of forces of the nature $$r^n$$, we usually take $$0$$ as the reference and integrate from $$0$$ to some $$r$$. In general, we are free to choose any reference and any limit, even though some are much more convenient, right ? In theory, we can choose any point, right ?

As long as we have :

$$U_a-U_b=-\int_b^a F.dx$$ we can choose any $$a$$ and $$b$$, and set either of $$U_a$$ or $$U_b$$ to be the reference and equal to $$0$$, right ?

Setting $$x=0$$ as the reference point means you are looking at the work done by the spring from $$x=0$$ to the end position $$x$$. Since $$W=-\Delta U=-\frac12kx^2$$, this will always be negative, which makes sense since the spring force always points towards $$x=0$$, and thus will point opposite the displacement.
In general $$W_{a\to b}=-(U(x_b)-U(x_a))=\frac12k(x_a^2-x_b^2)$$ and this is positive whenever $$x_a^2>x_b^2$$