Cracking your neck involves sudden and forceful twisting or bending of the cervical spine. Most of the time, its harmless.
It helps provide some relief to stiff and uncomfortable neck by stretching out the muscles, especially the shorter paravertebral muscles.
The sound comes from stretching the facet joint capsules (facet joints are small joints along the side of the spine, there are two facets at each spinal level), similar to cracking your knuckles.
It is dangerous if you have a small tear in your cervical disc and with this sudden neck rotation, you can cause yourself to have a slipped disc. If the slipped disc fragment is big, you may even need surgery.
Generally, I do not recommend cracking your neck. Gentle rotation and lateral flexion will also provide your the necessary muscle stretch for neck muscle tightness.