A compass has a small balanced pointer that always points North-South. This is because:
The earth has a magnetic field and the pointer is magnetic
The magnetic compass is the oldest instrument for navigation and has been a vital tool for navigators at sea for centuries. The Earth has a substantial magnetic field. The poles of the earth act as magnetic poles, as such a bar magnet, when suspended freely gets attracted towards the poles of Earth. So, it aligns itself in a North-South direction.