Two conservation laws, one circuit
Every circuit simulator, from a hand calculation on paper to full SPICE software, ultimately rests on two rules Gustav Kirchhoff wrote down in 1845 while still a student. They are not approximations - they are exact statements of conservation of charge and conservation of energy applied to an electrical network, and together they are enough to solve for every voltage and current in a circuit of arbitrary complexity.
Kirchhoff's Current Law
Kirchhoff's Current Law (KCL) says that the sum of currents flowing into any node equals the sum flowing out - equivalently, the signed sum of all currents at a node is zero. This is charge conservation: charge cannot pile up or vanish at a junction, so whatever flows in this instant must flow out.
sum(I_in) = sum(I_out) at every node equivalently: sum(I_k) = 0 (currents leaving the node taken as positive)
Kirchhoff's Voltage Law
Kirchhoff's Voltage Law (KVL) says that the sum of voltage rises and drops around any closed loop is zero. This is energy conservation: if you walk all the way around a loop and add up every gain and loss in electric potential, you must return to exactly where you started, since potential is a well-defined function of position.
sum(V_k) = 0 around any closed loop (rises positive, drops negative, consistent direction)
KCL and KVL are not independent tricks - they follow from Maxwell's equations in the quasi-static limit (frequencies low enough, or wavelengths long enough compared with the circuit, that propagation delay and radiation can be ignored). KCL is Gauss's law applied to a small volume around a node with no charge accumulation; KVL is Faraday's law applied to a loop with negligible time-varying magnetic flux through it. At radio frequencies, when circuit dimensions become comparable to a wavelength, this quasi-static assumption breaks down and you need full transmission-line or electromagnetic analysis instead.
Turning laws into a solvable matrix
By hand, KCL and KVL let you write down enough independent equations to solve any circuit, but modern circuit solvers formalize the process as Modified Nodal Analysis (MNA), the technique used inside SPICE and every derivative of it. MNA treats every node's voltage (relative to a reference ground node) as an unknown, writes one KCL equation per node - the sum of currents leaving through every resistor, capacitor and source connected to it must be zero - and assembles all of those equations into one linear system G·V = I, where G is a conductance matrix, V is the vector of unknown node voltages, and I is a vector of known current sources.
for each two-terminal element between nodes i and j with conductance g:
G[i][i] += g; G[j][j] += g
G[i][j] -= g; G[j][i] -= g // this is the "stamp"
# independent current sources add directly to the I vector;
# voltage sources need an extra unknown (their own current) and an extra KVL row - hence "Modified" nodal analysis
solve G * V = I for V
This element-by-element "stamping" procedure is what makes MNA practical for automated tools: each component only ever touches the rows and columns of the nodes it is connected to, so building the system for a circuit with thousands of components is just thousands of small, local, four-entry additions to a sparse matrix, followed by one linear solve. Reactive elements (capacitors, inductors) are handled by discretizing their differential current-voltage relationship in time and folding the result into the same conductance-matrix form at each simulated time step; AC analysis instead replaces every element's real conductance with its complex impedance and solves the same linear system with complex numbers.
A worked example: two resistors and a source
For a simple series circuit - a 12V source driving two resistors R1 and R2 in series - KVL around the single loop gives 12 = I*R1 + I*R2, so I = 12/(R1+R2) directly. For a circuit with a branch point, say R1 from the source to a middle node and then R2 and R3 in parallel from that node to ground, KCL at the middle node states that the current entering through R1 equals the sum of the currents leaving through R2 and R3, giving one equation in one unknown node voltage that, once solved, hands you every current in the circuit via Ohm's law.
Frequently asked questions
What is the physical reason KCL and KVL must hold?
KCL follows from conservation of electric charge: charge cannot accumulate at an ordinary circuit node, so whatever current flows in over any instant must flow out. KVL follows from conservation of energy (and the fact that electric potential is a well-defined function of position in the quasi-static regime): walking around any closed loop and summing potential changes must return you to your starting potential, a net change of zero.
Why do circuit solvers use nodal analysis instead of directly applying KVL to every loop?
Because for a large circuit, tracking every independent loop and every possible current path by hand does not scale, while every circuit has a well-defined and much smaller set of nodes. Modified Nodal Analysis writes one KCL equation per node, assembles them automatically as a matrix via simple per-component 'stamping' rules, and solves the whole system with one linear solve - which is exactly the kind of repetitive, structured problem a computer is good at.
Do Kirchhoff's laws work for AC circuits too?
Yes, with complex numbers standing in for magnitude and phase. KCL and KVL hold at every instant for AC just as they do for DC; the standard trick is to represent sinusoidal voltages and currents as complex phasors and replace resistances with complex impedances, after which the same G·V = I matrix formulation, and the same stamping procedure, applies unchanged.
Try it live
Everything above runs in your browser — open Kirchhoff Laws and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Kirchhoff Laws simulation