Grab the earbuds and hold them against your palm like this...
Then wrap them in a figure-8 around your index finger and pinky.
Then, when you have about 15cm left of wire, wrap it around the centre of the figure-8. This bit can be a little tricky.
Once you have wrapped it around a couple of times, it is safe to pull it off your hand, and keep going until you run out of wire.
Then, with the last little bit, tuck it under another bit of wire.
And your done! But to get them out...
By holding the plug, (be sure to untuck) and the earbuds, and pulling, your headphones should come out untangled.