I understand that it’s stopping the shrapnel from spreading, but how exactly does it work?

When tony was attacked with a bomb, small metal particles entered his body. And there was a high risk that those small metal particles would flow through his blood and enter hsi heart which would kill him. The doctor made an electro magnet and put it in tony’s chest(near his heart). This would keep metal scraps away from flowing into his heart.

Let me you through, step by step.
* Tony Stark (A.K.A Ironman, owner of Stark Industries) was attacked after a military missile presentation and was taken away by terrorists. Due to the blast near him he got fine metal scraps in his body which could flow into his heart and would kill him

* Now, the terrorist wants Tony Stark to build them weapons. So, they get a doctor to fit an electromagnet in Tony Stark’s chest to keep those scraps from flowing into his heart. The electromagnet is connected to a battery, this requires Tony to carry that heavy battery everywhere.

* To solve this problem, Tony Stark builds himself an miniaturized Arc Reactor (a small but highly durable power source) to run his electromagnet. He then inserts that Arc Reactor in a cavity on his chest. Later, Tony uses this Arc Reactor’s enormous energy to power his armor suits (we call Ironman)

* Much later (in Ironman 3), Tony Stark finally gets those metal scraps out of his body, through an operating. Now he uses Arc Reactors only to power his suits. He doesn’t have Arc Reactor in his chest anymore but all his suits have them inbuilt.

It uses a Electromagnet to stop the bomb fragments from entering his heart and killing him.
Also later after he made the arc reactor, it was used to power his various suits.

Mystery020 well done bro u have explained everything so clearly and with a lot of patience

It avts as a magnet and keeps rhe particles stable in his body moreover it acts as a onstant source of energy for tony