Justin Baeder / Flickr, CC It happens to everyone who owns an iPhone: You reach into your bag or pocket to listen to some music or take a call, and your earbuds have conspired against you. They've tangled themselves into a knot so vicious that you risk snapping the wire to get them undone (especially the little thin wires that go to each earpiece).

It happens to all earbuds, not just Apple's, but iPhone tangles seem more visibly conspicuous because their wires are white as part of Apple's branding.

Strangely, the knots even occur when you coil them carefully before putting them away. Unless they're on that plastic spindle that came with the box — and no one ever keeps that — those headphone wires will knot themselves on a daily basis.

It turns out that there is a reason this happens, and it has been the subject of scientific research. iPhone earbud tangles are a function of the length of the wire and the amount of "agitation" the wire is subjected to. When the two are plotted against each other — length versus agitation — the rate of knots and tangles obeys a statistical pattern that describes a curve.

A paper titled "Spontaneous knotting of an agitated string" by Dorian M. Raymer and Douglas E. Smith of the University of California at San Diego Department of Physics demonstrated this phenomenon: It revealed that a cord of less than 46 centimeters in length (about 1 foot six inches) will almost never tangle itself when sealed inside a rotating box for a period. But between 46 centimeters and 150 centimeters (about five feet), the probability of a knot forming rises dramatically. With a cord longer than that, the probability of a knot forming reaches a plateau of 50%. It turns out that the odds of getting a knot do not go higher because the cord wedges itself inside the shape of the box and that prevents further tangles from forming. Raymer and Smith performed 3,415 trials to demonstrate this.

Here is what that curve looks like:

PNAS

Apple's iPhone earbuds are 139 cm (55 inches) long and thus right at the 50% tangle-rate-sweet-spot at the top of the curve.

In other words, if you place your earbuds in a bag the odds of them tangling into a knot as you carry them around are 50%, at least. "At least" because earbuds are, of course, a Y-shaped string, and thus the knotting frequency is confounded further. (Raymer and Smith didn't look at strings with more than one branch, but anecdotally I can confirm that the tangle-rate is pretty high.)

Finally, here is a schematic showing how a cord that starts off neatly coiled — you don't just stuff them in there, do you? — quickly becomes tangled inside a rotating box, even though there is no gremlin inside tying them into reef knots. It shows that one end of a wire only has to cross another part of the wire twice in order to start spontaneously knotting itself:

PNAS

That last part is perhaps the most magical of all: The research shows that your earphones are indeed spontaneously knotting themselves. Sure, it's because of their length and the agitation of the container they're in. But the knots really do form as a matter of physics, not because of your personal lack of neatness.

Though Apple has shipped its white in-ear headphones with every iDevice since the iPod in 2001, Apple most recently updated its earbuds — now called "EarPods" — in late 2012. Hopefully Apple will pay attention to the science of tangling — and its own patent application filed in 2011, which proposed thicker wires to prevent bending and looping — when it decides to release new earbuds at some point in the future.