how to get rid of a stiff neck

Use moist heat on your neck. Heat helps tightened muscles relax, [1] and moist heat is better than dry heat, as it can penetrate into the neck more effectively.[2] Apply heat to the back or neck area for at least 20 minutes at a time, three times daily.
A moist heating pad (available at drug stores) is the best choice for applying heat to your neck, as the temperature can be controlled and applied for longer periods of time. Alternately, use a hot water bottle or take a hot shower or bath.

Place a hot towel over your neck. Place a hand towel in a bowl full of hot water, or pour the hot water all over the towel. Alternatively, put the towel in the dryer for 5-7 minutes. Dry out the towel just enough so that it is not dripping, but still has its warmth. Drape the towel over your neck when your neck is stiff or sore. After that is done wait about 20 minutes a do it again. Keep doing this about three times.

Try an ice pack to soothe your neck. Cold dulls local pain and limits the buildup of lactic acid, which can cause soreness.[3] Use an ice pack and place it on the part of your neck that feels stiff (usually the back of your neck at your hairline). Hold the pack there for 10-15 minutes every 2 hours.[4]
You can also try a more comfortable position to ice your neck. Sit in a comfortable chair and rest your head back. Place the pack between your shoulders and the bottom of your head. Lean back against it so your neck gets the full benefit of the cool temperature.
Some experts feel that ice will contribute to increased stiffness in the neck because the cold will contract your muscles.[5] Try what feels good to your neck.
Use a cold treatment for acute pain in the first 48-72 hours, and then switch to heat.[6]

Nod your head forward and backward. In most cases, a stiff neck can be relieved immediately by performing a series of exercises to relieve tension caused by tight or strained neck muscles. Stretch the muscles in the front and back of your neck by tilting your chin toward your chest. Then bring your chin up toward the sky. Repeat for several minutes.
If this exercise feels painful, don’t tilt your head too far forward or backward. Just try enough movement to feel a little stretch.