Electromagnetism
Kirchhoff's Laws
Two laws (current at nodes, voltage around loops) that solve any circuit
Kirchhoff's circuit laws (1845) are two principles that, combined with Ohm's law, solve any electrical circuit. KCL (Kirchhoff's Current Law) — sum of currents into a node equals sum out (charge conservation). KVL (Kirchhoff's Voltage Law) — sum of voltage drops around any closed loop equals zero (energy conservation). Foundational for circuit analysis.
- KCL (Current Law)Σ I_in = Σ I_out at every node
- KVL (Voltage Law)Σ V drops = 0 around any closed loop
- SourceCharge and energy conservation
- DiscovererGustav Kirchhoff, 1845
- Combined with Ohm's lawSolves arbitrary linear circuits
- Multi-loop circuitsMesh analysis (KVL) or nodal analysis (KCL)
Interactive visualization
Press play, or step through manually. The visualization is yours to drive — try it before reading on.
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
Statement of laws
KCL (Current Law): The algebraic sum of currents at any node is zero.
Σ I_in = Σ I_out (at every node)
KVL (Voltage Law): The algebraic sum of voltage drops around any closed loop is zero.
Σ V_drops = 0 (around any closed loop)
How to apply
- Identify nodes (junctions where 3+ wires meet) and loops (closed paths).
- Assign current direction to each wire (arbitrary; sign of answer tells you actual direction).
- Apply KCL at each node — Σ I = 0.
- Apply KVL around each independent loop — Σ V_drops = 0.
- Use Ohm's law (V = IR) to relate V and I at each resistor.
- Solve the system of equations.
Example: two-loop circuit
Battery V₁ in loop 1, battery V₂ in loop 2, resistors R₁, R₂, R₃ shared.
Mesh analysis with loop currents I₁ and I₂ (each loop's "circulation"):
Loop 1: V₁ = I₁·R₁ + (I₁ - I₂)·R₃
Loop 2: V₂ = I₂·R₂ + (I₂ - I₁)·R₃
Two equations, two unknowns (I₁, I₂). Solve via substitution or matrix.
JavaScript — circuit analysis with Kirchhoff
// Solve simple two-loop circuit using mesh analysis
function twoLoopCircuit(V1, V2, R1, R2, R3) {
// Mesh equations:
// V1 = I1·(R1 + R3) − I2·R3
// V2 = -I1·R3 + I2·(R2 + R3)
// Or: V1 = I1·R1 + (I1-I2)·R3
// V2 = I2·R2 + (I2-I1)·R3
const A = [
[R1 + R3, -R3],
[-R3, R2 + R3]
];
const b = [V1, V2];
// Solve 2x2 linear system
const det = A[0][0]*A[1][1] - A[0][1]*A[1][0];
const I1 = (b[0]*A[1][1] - b[1]*A[0][1]) / det;
const I2 = (A[0][0]*b[1] - A[1][0]*b[0]) / det;
return [I1, I2];
}
// Example: 6V battery, 3V battery, R1=R2=R3=1Ω
const [I1, I2] = twoLoopCircuit(6, 3, 1, 1, 1);
console.log(`I1 = ${I1.toFixed(2)} A, I2 = ${I2.toFixed(2)} A`);
// Verify KVL
function verifyKVL(V1, I1, R1, I2, R3) {
// Loop 1: V1 - I1·R1 - (I1-I2)·R3 should = 0
return V1 - I1*R1 - (I1-I2)*R3;
}
console.log(`KVL check: ${verifyKVL(6, I1, 1, I2, 1).toExponential(2)}`); // ~0
// Voltage divider: simplest KVL
function voltageDividerKVL(V_in, R1, R2) {
// V_in = I·R1 + I·R2 → I = V_in / (R1+R2)
// V_out = I·R2
const I = V_in / (R1 + R2);
return { current: I, V_R1: I*R1, V_R2: I*R2 };
}
console.log(voltageDividerKVL(9, 100, 200));
// Current divider: simplest KCL
function currentDividerKCL(I_total, R1, R2) {
// Both branches at same V; I = V/R; total V = I·(R1·R2/(R1+R2))
// Currents: I1·R1 = I2·R2 = V (both branches have same V)
const V = I_total * R1 * R2 / (R1 + R2);
return { I_R1: V/R1, I_R2: V/R2, V_branch: V };
}
console.log(currentDividerKCL(2, 100, 200));
// Bridge circuit balance condition
function isBridgeBalanced(R1, R2, R3, R4) {
// Wheatstone bridge balanced when R1/R2 = R3/R4 → no current in galvanometer
return Math.abs(R1*R4 - R2*R3) < 1e-9;
}
console.log(isBridgeBalanced(100, 200, 1000, 2000)); // true (1:2 ratios match)
console.log(isBridgeBalanced(100, 200, 1000, 2100)); // false
// Simple node analysis: 3 nodes, 5 branches example
function nodalAnalysisExample(V_source, R1, R2, R3) {
// Star network: ground at one node, V_source connected to another
// Various paths
// For specific example, write equations and solve
// (Skipping general implementation — too complex for snippet)
return "Use SPICE for general circuits";
}
Where Kirchhoff's laws matter
- Circuit design. Foundation of all analog and digital circuit analysis.
- SPICE simulation. Industry-standard tool — solves Kirchhoff's equations numerically.
- Power grid analysis. Massive application; load flow studies use generalized Kirchhoff.
- Operational amplifiers. Op-amp circuits analyzed via KCL/KVL with assumption of "virtual short" between inputs.
- Bridge circuits. Wheatstone bridge for sensitive resistance measurement.
- Education. Bedrock of EE curriculum; first lawyers learn after Ohm.
- Filters and amplifiers. All audio, RF, signal-processing circuits use KVL/KCL methods.
Common mistakes
- Sign errors. Trace direction matters. Be consistent — voltage rise (− to +) is positive going one way; drop the opposite. Currents arbitrary direction; sign tells you actual.
- Missing node or loop. Identify all nodes and select independent loops. Don't double-count or miss any.
- Confusing series and parallel. Series — same current. Parallel — same voltage. Mistakes break KCL/KVL.
- Forgetting capacitor and inductor V-I relations. For DC steady state, capacitor open (I=0), inductor short (V=0). For AC, use impedances.
- Ignoring polarity of sources. Battery's + side is higher V than − side. KVL must account for this consistently.
- Treating reciprocal-resistor problems as additive. Resistors in series add; in parallel, reciprocals add. Capacitors are opposite. Don't mix up.
Frequently asked questions
Why does KCL hold?
Conservation of charge. Charges can't pile up at a node (a junction in the circuit). Whatever flows in must flow out. Mathematically, if K wires meet at a junction with currents I_1, I_2, ..., I_K (positive into node, negative out), then ΣI_k = 0.
Why does KVL hold?
Conservation of energy. As you trace a closed loop, voltage rises (going through battery) and drops (through resistor) must balance. The work done on a charge going around a closed loop must be zero (otherwise free energy from nothing).
How do you apply Kirchhoff's laws?
Identify all nodes and loops. For each node, write KCL. For each independent loop, write KVL using Ohm's law (V = IR for resistors). Solve system of equations for unknown currents/voltages. Number of independent equations equals branches; can systematically reduce.
What's mesh analysis vs nodal analysis?
Mesh — assign loop currents, write KVL for each. Nodal — assign node voltages relative to ground, write KCL at each. Both work; pick whichever has fewer equations. Mesh good for circuits with many series elements; nodal good for parallel branches.
Do Kirchhoff's laws work for AC?
Yes — same form, but use complex impedances (Z) instead of resistances. KCL and KVL still hold (charge and energy conservation). For sinusoidal steady-state, replace V = IR with V = IZ where Z is complex.
When do Kirchhoff's laws break down?
At very high frequencies where wavelength approaches circuit dimensions — capacitive and inductive coupling matter, and "lumped element" model fails. Need full Maxwell's equations and transmission-line analysis. Also fails when significant EM radiation exits the circuit.
How do voltage and current sources count?
Voltage source — fixed V across it, regardless of current (ideally). Current source — fixed I through it, regardless of V. In KVL, voltage source adds/subtracts its V. In KCL, current source adds/subtracts its I. Use polarity conventions consistently.