Why do we include $x$ in this Spring Equation? I am currently in Physics 1 and we are learning about Energy. This may sound like a dumb question but I am currently trying to understand this. Here is the question of the problem: 

A 10kg block is dropped from a height of 20meters onto a spring with a spring constant of 2500Nm. How much will the spring be compressed?

My initial equation was: $$PE_i = PE_f \implies mgh = \frac12kx^2$$
I was wrong and the actual equation that should have been used was:
$$mg(h+x) = \frac12kx^2$$
My question: Why is it $mg(h+x)$ instead of $mgh$?  
 A: The other answer is right, but I find it a little hard to read.  Here is my attempt to clarify.
The total amount of energy never changes.  It just moves between three compartments: gravitational potential energy, spring potential energy, and kinetic energy. 
Two of these compartments have natural zeros: kinetic energy is zero when the block isn't moving, and spring potential energy is zero when the spring is not compressed.  But when it comes to the third compartment--gravitational potential energy--you get to choose where zero is. In your answer, you have chosen it to be zero when the block first touches the spring: that's how you get $PE_i=mgh$.  
Since kinetic energy is zero when the block reaches its lowest point, all the energy at that point is in the other two compartments.  The spring potential energy, as you surmise, is $\frac{1}{2}kx^2$, but the gravitational potential energy is not zero--you already decided that it's zero when the spring is uncompressed.  Since you've moved down from that point by a distance $x$, the gravitational potential energy is negative: it's $-mgx$.
So, $$PE_i = PE_f \implies mgh = \frac12kx^2 - mgx.$$
A: The spring is not stable state even after the ball fell h height ie the ball continues to move a x distance . Now due to restoring force and velocity the ball proceeds furuher to extend the spring. Now with respect to the heighest extension of spring the potential energy of the spring is $mg(h+x)$ which is equal to work done by the wire for extending and also the gravity does work +mgx after the fall of height h of the block so the potential energy stored indeed was mg(h+x). (Note that the spring only applies restoring force after passing the equilibrium  position because before that the spring was slack . So energy loss by spring is just $kx^2/2$ ; not $k(x+h)^2/2$. ) And also note that the potential energy is calculated with respect to the mean position of the spring ie the most bottom point of the spring after being streched). 
