The cathode is the electrode where the direction of the electric current is from the electrolyte (soil, water) towards the metal object to be protected. The anode is the electrode where the direction of the electrical current is from the metal object to the solution.
Do you recognise it? Many people tend to forget the flow of the electrons and what should be called the anode and what the cathode.
The basic principle for cathodic protection is to connect a metal with a less noble metal. In a electrically conductive solution the, less noble metal will start to corrode and the more noble metal will be protected against corrosion.
In this example, the Fe object is said to be the cathode and the Mg sacrificial metal the anode. And the essence of protection is there: The Fe object is cathodically protected by the Mg anode. Of course there are more methods that using just sacraficial anodes. Active electronic systems, like impressed current systems are becoming more widely used.
Read more about cathodic protection in this article.