The magnets have different poles of magnetic interaction, responsible for their power of attraction or repulsion. It is observed that when we approach poles of the same characteristic, equal, repulsion occurs between them, and when we approach poles of different characteristics, attraction occurs.
Earth is a great natural magnet that features a south pole and a geographic north pole. The geographic north pole of the earth is called the south magnetic pole, and the geographic south pole is called the north magnetic pole of the earth, these poles interact with the poles of the magnets causing attraction and repulsion.
When we arrange a magnet so that it can rotate freely, we observe that it moves and stops in a position oriented by the direction of the north and south magnetic poles of the earth. This displacement is caused by the interaction between the magnetic poles in the magnet and the magnetic poles of the earth.
As the attraction between the poles only occurs if they are different and the repulsion if they are the same, the magnetic poles of the magnets were assigned the same names of the geographic poles of the earth. So when the north pole of a magnet submits to the earth's magnetic south pole, it will rotate and position itself towards the geographic poles of the earth and the end of the magnet facing the geographic North of the earth is called the magnet's MAGNETIC NORTH POLE and its opposite will be the SOUTH MAGNETIC POLE.
This is the reason why the north pole of the magnet of a compass always points to the magnetic south pole of the earth.
In this way to better represent the attraction and repulsion between the poles of a magnet we can say that poles of equal names repel each other and poles of different names attract.