Anyone who’s grappled with jumbled headphones knows the difficulty of disentangling snarled cords. A tight knot is nothing for a California blackworm, however. These tiny worms twist together by the thousands to form tightly packed blobs reminiscent of a forkful of squirming spaghetti. While these tangles take minutes to form, intertwined blackworms can wriggle free in a matter of milliseconds.

Now scientists have finally straightened out how these legless escape artists use only a simple collection of muscles and neurons to seamlessly slither out of tight tangles. “We thought that if worms can solve this untangling problem, so could we,” says Vishal Patil, an applied mathematician at Stanford University. In a study published today in the journal Science, Patil and his colleagues used mathematical simulations to pinpoint the movements blackworms use to rapidly untangle themselves.

At just a couple of centimeters long, California blackworms (Lumbriculus variegatus) are easy to overlook. Yet these aquatic worms, which are common grub for aquarium fish, exemplify strength in numbers. To conserve their moisture or maintain their temperature, anywhere from five to 50,000 blackworms intermingle to form writhing blobs seemingly right out of a creature feature. While these tangles are tight, the earliest sign of a predatory diving beetle will send the fleshy worms squirming in all directions.

Harry Tuazon, now a bioengineering Ph.D. student at the Georgia Institute of Technology, caught a glimpse of this nearly instantaneous response when he observed blackworms wriggling across a petri dish in the lab. “I pointed a UV light toward a ball of worms, and it suddenly exploded,” he says. “It was mesmerizing.”

Tuazon became enamored with these worm balls, which unraveled in a few tens of milliseconds—a fraction of an eyeblink. He took microscope videos of the movements of individual worms before gradually adding more of the animals to the mix to increase the complexity of the balls. To untangle the physics behind these worm webs, he teamed up with Patil, then a Ph.D. student at the Massachusetts Institute of Technology specializing in the geometry of knots and other complex systems.

Patil noticed something interesting when he watched microscope videos that Tuazon had shot of a single worm responding to a small electric shock. As the worm reacted to the stimuli, it moved its head clockwise before reversing course and turning counterclockwise in a repeating motion. This created a figure-eight pattern known as an alternating helical wave.

To create accurate mathematical models of the worms’ helical gait, Patil also needed to see how the individual worms moved inside the tangles. This proved difficult for Tuazon because the worm balls were surprisingly impenetrable. The worms were submerged in water, so x-rays proved unsuccessful. Microcomputed tomography scans only offered low-resolution glimpses. Finally, Tuazon determined that the team’s best bet was sound. He used an ultrasound machine to create images of a cluster of living worms that were placed inside gelatin.

The ultrasound images allowed the researchers to plot more than 46,000 points of data on the movements of the individual worms, who were constantly in contact with other worms inside the writhing jumble. Patil and his colleagues created mathematical models of the worms’ movements and ran them through three-dimensional simulations of the tangles.

The researchers found that employing the alternating helical gait motion allowed the worms to seamlessly untangle themselves. They also found that a slightly altered movement, where the invertebrates corkscrewed in mostly one direction, helped create the tangles. “If it spends longer winding in one direction before switching to winding in the other direction, you get the tangling behavior,” Patil says. “If the worm rapidly switches between winding clockwise and anticlockwise, you get untangling behavior.”

According to Eleni Panagiotou, a mathematician at Arizona State University, who studies the effects of entanglements in physical systems, the versatility of this movement allows the worms to fine-tune their tangles. “California blackworms [exhibit] this optimal threshold where they can both tightly entangle and disentangle quickly,” says Panagiotou, who was not involved in the new study but wrote a related perspective piece in Science. If they twist too much, the tangle becomes too tight, and the worms lose their ability to escape. If they don’t twist enough, the protective tangle won’t form.

She thinks similar motions can help untangle an array of complicated knots, which are ubiquitous in both nature and the artificial world. For example, tangled filaments naturally occur in everything from gnarled root networks to tightly wound DNA strands. Humans have long employed tangles to fashion rope and weave fabric. “The researchers not only explain what nature is doing in these worms, but they also create a map of the possibilities in other systems and contexts,” Panagiotou says.

The team thinks these worms’ movements can possibly help researchers program stringlike filaments in soft robotic systems to actively shape-shift. This could create flexible bandages that change shape as wounds heal or water filters that can be fine-tuned to sift out certain particles.

Patil thinks the proof is in the worm blob. “These worms give us the general principles behind tangling and untangling and potentially a toolbox for manipulating other systems,” he says. “It's not just a mathematical model because we know that worms can do it.”