A spring is a device that relates force (f) to displacement (x).

Each spring has a constitutive law, expressed as either a graph or an equation, relating f to x.

Most springs are designed to be linear, at least over a certain range. The linear constitutive law of a spring is:
F = kx
where F is the force being applied to the spring, k is the spring constant (the larger k is, the stiffer the spring is), and x is the difference between the current length of the spring and its relaxed length, x0.
This equation is referred to as Hooke's law.

Force and displacement are vectors, meaning they have direction as well as magnitude. Hooke's Law is often written
F = -kx
to emphasize the fact that the force exerted by the spring is in the opposite direction of the spring's motion (displacement).

The force is always the same at both ends of a spring(see: through variable). If the force is positive, the spring is in tension. A negative force means that the spring is in compression.

Likewise, the displacement is positive when the spring is in tension, negative when it is compressed. Displacement of a spring is an across variable.

NOTE: Velocity is not directly related to force for springs. A spring can have a positive force and displacement, and still have a negative velocity.
Consider a stretched spring being allowed to slowly relax. As the spring relaxes, its velocity is negative (it is shortening from end to end), while the force and displacement are still positive until it reaches its relaxed length.