When you sleep on your stomach, it can cause back strain and hurt your neck.
Sleeping on your back puts extra pressure on it. You can reduce that by sleeping with a couple of pillows under your knees. Resting on your side with a pillow between your knees also helps.
To help your back while you’re awake, keep a healthy weight, sit with your knees a little higher than your hips. Stop smoking too. It cuts blood flow to your discs, making them less cushiony.