I want to design a DC solenoid valve that could compress a spring under 5 kg of load. All I know is the voltage (12V), load (5kg), the current range (15-20), and the cross-sectional area of the winding. kindly help me with the number of turns, wire gauge, etc.
You can do this experimentally, or look up someone who has done measurements and calculations and published them. One such reference is this one from 1910, when electromagnets and solenoids were hot stuff.
There is far too much there to distill into a reasonable length answer and I don't think it would be particularly helpful to others, so regrettably this will be essentially a link-only answer, and also I encourage you to search for other references which may be easier to use.
To add to the other answers here, this sort of a design problem is actually an excellent use case for the freeware magnetics simulator FEMM (Finite Element Method Magnetics): https://www.femm.info/wiki/HomePage
In particular, take a look at the "force on a plunger magnet" example: https://www.femm.info/wiki/RotersExample
FEMM can't do full 3D simulations, however, it can do axisymmetric simulations (ie: simulations with radial symmetry). Since pretty much any solenoid will by radially symmetric (barring some unusual geometries), it should work pretty well for your use case.
At minimum, you'd model two cases: one case where the armature is fully retracted (to ensure that the solenoid generates enough force to overcome the compressed return spring + required holding force of the mechanism), and one where the armature is out at full travel (to ensure that the solenoid has enough force to overcome the uncompressed spring). If you need to do more, you can also programmatically alter the geometry with MATLAB or Octave, so you can step the armature position and generate a force vs. position graph to ensure that you are generating enough force at every point through the stroke for your mechanism.
Force of solenoid comes from an effort to neutralize the unbalance magnetic force induced to the arm core inside the solenoid. That force will press or pull one side to make it center. In your case, it will press, press the spring which the load is 5kg (around 50N). Current (I) is number of voltage over resistor (V/R), which R is the resistor of the solenoid. For this R, you must measure it with AVO meter. Pick one size coil conductor then put to the equation below:
F = (N * I)^2 x magnetic constant * A / (2 * g^2),
^ is mean power of, power of 2 in this case.
F is the force exerted by the magnetic force inside the solenoid, which in your case is 5kg*9.81km/m^2 or around 50N.
magnetic constant=4pi10^-7 H/m (this is left question, why magnetic permeability of the core is always put air).
N is number of turn,
I is the current flow through the solenoid (V/R).
A is cross sectional area (assume you have cross sectional diameter = 5cm or 0.05m).
g is length of the solenoid, probably 1 cm or 2 cm (0.01m or 0.02m). It is normally denoted as l (small letter of L, while L capital is denoting inductance).
was also long time confusing for me about the gap, but thanks to Mr. David Cope in the reference 4 below that here wrote the equation, and we may compare it to Wikipedia to get what is it.
By knowing the parameters and by using calculator in reference 2 and 3 below, you may easily get the required.
Reference: How to Calculate the Force of an Electromagnet, Solenoid (Electromagnet) Force Calculator, Solenoid Electromagnetic Force Calculator, and compare the first reference to this answer by Mr. David Cope here and to this Wikipedia.