Almost every guy has experienced it at one point or another in his life: an aching, heavy ballsack that just holds on for too damn long. It's "blue balls", or as it's called in the medical community, "epididymal hypertension". But just what has happened to bring on this terrible feeling in your nuts? You were aroused for a long time and didn't cum soon enough, or at all.
The science behind blue balls is simple: when the male body is aroused your circulatory system sends more blood to the genitals to make an erection happen. While most of that blood is sent into the penis, some of it also goes to your testicles. When you're aroused your balls actually grow slightly with the increased blood flow.
Once the need for the erection has passed, either you've calmed down or you've ejaculated and like most guys your boner and sex drive immediately starts winding down, the clamped down veins that were keeping blood in your genitals to sustain the erection relax and the blood flows away. Bye bye erection.
But if you stay hard for a long time without orgasming — either the arousal goes away or it just takes a long time for you to ejaculate — then that blood can pool. Common situations in which this may occur are sustained arousal when you're not engaged in sexual activity and edging where you work to delay orgasm. That pooling of blood in your scrotum distends the blood vessels inside, making it feel heavier and causing minor aching pain throughout the groin. Your sack could even take on a slightly bluish hue from the trapped low-oxygen blood, but this doesn't happen to all me. It can take a few hours, but eventually that blood will drain out of your ballsack and the pain will subside and the coloration will return to normal.
There are other potential causes of testicular pain that typically will not resolve as quickly, including epididymitis (an infection in the scrotum), kidney stones, mumps, testicular cancer, and testicular torsion. If testicular pain isn't from a known source (e.g. you got hit in the crotch) and doesn't subside within a few hours, you should contact your doctor immediately.
While you could wait for the discomfort of blue balls to subside, there's a much simpler and more enjoyable remedy you can employ: masturbate. Don't edge or do anything that could prolong the blue balls — just a simple, to-the-point, meat beating all the way to the point of cumming will help your body send the right signals to your blood vessels to relax and let the blood drain out. Relief will cum come almost right away.