A magnet is an object or material that can produce a magnetic field of its own. That magnetic field is responsible for the property of magnets to attract or repel other magnets, and pull objects that are ferromagnetic, like iron. Electrons are the reason behind the production of magnetic fields and magnetism. In permanent magnets, spinning of electrons creates the magnetism.
In most materials, the arrangement of atoms is such that the electrons cancel the magnetic orientation of each other. In the atomic makeup of ferromagnetic substances, areas known as domains are formed by smaller groups of atoms. In domains, the magnetic orientation of all the electrons is the same. If the domains in an object or material are aligned in one direction, it becomes a magnet.
At room temperature, there are only four elements that are ferromagnetic: cobalt, gadolinium, iron and nickel. Dysprosium is an element that is ferromagnetic only at low temperatures. In electromagnets, movement of electrons through a conducting material is responsible for the generation of the magnetic field.
Each magnet has two poles: the north pole and the south pole. Field lines that start from the north pole of the magnet and end at the south pole are used for representing the magnetic field of that magnet.