Ants follow an indirect path across a surface of smooth felt (white) and rough felt (green), in order to reach their destination in the fastest time.

Just as light does, ants traveling through different materials follow the fastest path, not the shortest one.

A recent study found that when fire ants (Wasmannia auropunctata) crossed different surfaces, the insects chose the route that would minimize their total walking time, rather than the distance traveled. The ants' behavior offers a window into how groups of social insects self-organize, the scientists say.

In optics, a ray of light traveling between two points takes the path that requires the least amount of time, even if it's not the shortest distance — which is known as "Fermat's principle of least time." For example, imagine a lifeguard rushing to save someone in the ocean some distance down the beach. The quickest way for her to get to the victim would be to run along the beach first, in order to minimize the time she would have to spend swimming, which usually takes longer than running. [Album: The 11 Most Beautiful Math Equations]

In the study, researchers collected colonies of the little fire ant — one of the world's 100 most invasive species — at sites in Israel. Each colony contained a few thousand worker ants and several queens. The ants were placed in a corner of an enclosure, and cockroaches were provided as a food source in the opposite corner. To get to the cockroaches, the ants had to cross a foraging area covered with different materials: smooth felt, rough felt or a glassy surface. The scientists tested the ants on surfaces composed of pairs of these materials next to each other (glass and rough felt, glass and smooth felt, smooth felt and rough felt).

The ants traveled more quickly over the glassy material than they did over either type of felt, and they moved more rapidly over the smooth felt than over the rough felt.

En route to their roach banquet, the ants did not follow the most direct travel path, the study found. Rather, they followed an angled path, traveling over more of the smoother material in order to reach the food morsels in the shortest amount of time. The findings demonstrate that Fermat's principle of light travel also applies to living creatures, the researchers conclude.

The ants rely on trails of pheromones to find their way. The researchers suggest that the chemical trail might initially be random, but converges on the optimum route over time. This process illustrates self-organization and evolution, in which all possible routes are whittled down to the fastest one.

"We found that a general rule applies to a dynamic system that relies solely on communication [pheromones] and social cooperation," lead study author Jan Oettler of the University of Regensburg, Germany, told the news site Phys.org.

However, the ants have their limits. Over shorter distances, the ants didn't perform as well in choosing the fastest path, possibly because there was more of the pheromone in each area.

Scientists have long known that ants choose the shortest of several paths to get to a food source, in order to minimize travel time or conserve energy. For example, harvester ants avoid paths with more vegetation, and wood ants prefer horizontal bridges to vertical ones.

The new findings were published March 20 in the journal PLOS ONE.

Follow Tanya Lewis on Twitter and Google+. Follow us @livescience, Facebook & Google+. Original article on Live Science.