The video posted below explains that synovial fluid, a "lubricant-like substance" found in between the joints, releases a gas when you stretch out your knuckles.
This gas forms bubbles which pop, resulting in the cracking sound that so many people despise.
As for the age-old debate regarding the dangers of knuckle-cracking, Vox cites two studies.
The first won researcher Donald Unger the Ig Nobel Award in Medicine in 2009. After cracking the joints in his left hand, but not his right hand, for 60 years, he concluded that cracking joints would not cause arthritis.
On the other hand, Vox brings up a 1990 study that found that snapping, cracking, and popping can lead to a decrease in grip strength and an increase in hand swelling.
Here’s a video showing what happens when you crack your knuckles.