For ordinary earbuds like the Apple stock product I repeatedly fold the cable in half until I have just enough length to tie the bundle into a loose overhand knot. (Sounds like heresy, but I learned this technique for storing cables from a "big time" touring concert sound company.) Been practicing it with all sorts of cables for better than twenty years without any negative fallout.
I added this photo of my cord knot after this answer was accepted by Torben, who I believe was most interested in the Devil Horn Technique mentioned below.
After tying the initial knot in this particular cord bundle the loose ends were a little too long for pocket carry so I tucked them back into the center of the knot and pulled gently to tighten them into place, converting the initial overhand knot into a Double Overhand Knot
However, I do coil my good earbuds neatly and keep them in a little pouch. Same for the Jlab phone headset I use for every day carry.
If none of these techniques suit, there are many practitioners of what, for lack of a better description, is referred to as The Devil Horn Technique
Pretend you’re at a Def Leppard concert and make the devil horns with your left hand. (Don’t pretend you don’t know what I mean — middle and ring fingers bent and held down by the thumb, index and pinky extended.) Tuck the buds underneath the middle and ring fingers to secure them and use your devil horns as posts around which to loop the cord. (Some people advocate a figure-eight wrap, but I find a simple loop works fine.) Leave a couple inches of cord at the end. Slide the loop off the devil horns, and wrap the remaining cord around the middle of the loops, creating a little bundle. Thread the plug end through the loop opposite the buds and give it a gentle pull to tighten the bundle. This little package now fits neatly in your pocket, is almost entirely tangle proof, and unravels with ease.