A battery contains 2 electrodes: 1 anode and 1 cathode. The electrodes are immersed in an electrolyte solution. When a battery is inserted into a device, the circuit is complete and oxidation occurs at the anode when ions in the electrolyte solution react with the anode. As oxidation of the anode results in a loss of electrons, the lost electrons are gained by the cathode in a reduction reaction which occurs as the free electrons react with substances in the cathode. It is this flow of electrons that result in electricity. Electricity will be generated until 1 or both of the electrodes run out of substances required for the reaction to occur. This is why batteries go flat after some time!