A relay is an electrical switch that opens and closes under the control of another electrical circuit. The switch is operated by an electromagnet to open or close one or many sets of contacts.
A relay has at least two circuits. One circuit can be used to control another circuit. The 1st circuit (input circuit) supplies current to the electromagnet. The electromagnet is magnetised and attracts one end of the iron armature.
The armature is then closes the contacts (2nd switch) and allows current flows in the second circuit. When the 1st switch is open again, the current to the electromagnet is cut, the electromagnet loses its magnetism and the 2nd switch is opened. Thus current stop to flow in the 2nd circuit.