# Change in entropy of the Universe for charging/discharging a capacitor

I just need to know what exactly happens when charging/discharging a capacitor. Is there any heat transfer between the capacitor and the surroundings? Is there a heat transfer between other parts of the surroundings (wires, the battery)?

Another thing I don't understand generally... How do we know if a process is reversible or irreversible? Should we take the third law of thermodynamics as a principle and calculate the change in the entropy of the Universe through the formula given for entropy? If so, how about a process like the free expansion of a gas in which there is no heat transfer but the entropy increases? What about an adiabatic process? Where is the start point for calculating the change in entropy of the Universe for charging/discharging a capacitor?

In thermodynamics a process is reversible if it can be reversed by an infinitesimal change in the conditions, in other words everything is at the same temperature, pressure, etc (give or take an infinitesimal difference so that something actually happens) If energy is conserved in our process them the sum of all the heat transferred between different parts of our system must be 0. If, for a reversible change, everything is at the same temperature and $$\mathrm{d}S = \frac{\mathrm{d}Q_{rev}}{T}$$ This implies that the total change in entropy must also be 0.