Most of us take Earth's magnetic field - and our faithful north and south poles - for granted. Like a giant bar magnet, the magnetic field is always there, protecting us from space radiation and helping migratory animals to navigate around the world.

But the planet's magnetic field hasn't always been like this, and it won't stay this way forever. In fact, the poles are already starting to shift, and researchers predict that at some point, they'll flip, just like they've done many times in the past.

To understand what that means for us and when it might happen, scientists need to figure out what it might have looked like in the past.

The best way to do this is to get information from the magnetic minerals trapped in sedimentary rock, but up until now, geologists hadn't been able to show how those rocks became magnetised, so couldn't take much information from them.

Now, for the first time, a team of researchers from Russia has found evidence that these magnetic minerals could have been produced by ancient, sea-dwelling bacteria. And it looks like they could reliably hold a magnetic direction for billions of years.

If this is confirmed, scientists will be able to figure out how sensitive these particles are to the magnetic field, and how they were produced - which will give them unprecedented insight into Earth's magnetic field throughout history.

"With a few extra calculations, we can make an estimate of how strong Earth's magnetic field was at that time," geophysicist David Heslop from the Australian National University, who wasn't involved in the study, told Earth and Space Science News (Eos).

Researchers had long suspected that ancient, sea-dwelling bacteria were the source of iron-rich minerals inside sedimentary rock, seeing as they often poop out magnetic particles.

What was stumping them was the fact they'd never been able to experimentally show that microbes were capable of producing large enough particles to faithfully retain information about the magnetic field.

If a magnetic particle is too small, even a tiny amount of heat can cause its field to flip, and at room temperature, the magnetic orientation of small particles flip-flops all over the place constantly.

So without evidence that bacteria could make longer magnetic particles, researchers weren't sure that they could have been the source of the magnetism in ancient rock, and they've been forced to discount a lot of data in the sediment record.

To try and figure out what was going on, the Russian team took common bacteria and placed them in a glass jar of water, along with the kind of sediment you would have found in the oceans covering ancient Earth - iron, nutrients, and sand.

After two years, they tested the rust-coloured sludge that had formed at the bottom of the jar, and showed that not only had the bacteria been able to produce a whole heap of magnetic particles - such as magnetite, goethite, and lepidocrocite - they'd also produced many particles larger than 30 nanometres in length, which is big enough to hold a magnetic field for billions of years.

Sludge webLM Kondratyeva

"These particles confirmed for the researchers that given enough time, bacteria could prompt larger and larger magnetic crystals to grow in their environment, just by moving and stirring up the water and excreting iron-rich waste," Elizabeth Deatrick reports for Eos.

This means that all this magnetic bacteria poop could have settled on the bottom of the seafloor, and kept a faithful record of exactly what the magnetic field was like at the time.

Now that they know where the magnetic particles came from, scientists should be able to revisit a whole lot more ancient magnetic rocks. What they find might not only give us a better insight into the past, but could teach us some valuable lessons about what to watch for in the future when Earth's magnetic field inevitably flips - and how the shift might affect us and our telecommunication systems.

The research has been published in Geophysical Journal International.