There are no relevant clues in your past or personal histories.
No bad habits – you seem to be a gentleman!

If the duration of the pain has been short, it could be muscle spasm – from posture at work or sleep.
Simple pain reliever like paracetamol or ibuprofen may help.
Sometimes muscle relaxant may be taken in addition – combinations are available over the counter, in most pharmacies

If the duration is long / if there are associated symptoms like fever, swelling etc – you will need physical examination.
If the pain is persisting for long, you should see a doctor, for favour of further assessment and assistance. You may need MRI of the neck...

You are very young. Most probably, there may not be anything of concern.
Start regular exercise – it will be good in the long run