a chain complex
A chain complex is the bare algebraic skeleton on which all of homology hangs. Strip away the geometry of spaces and triangles, and what remains is a sequence of abelian groups with maps between consecutive ones, arranged so that doing two maps in a row gives zero. That single rule, applied over and over, is enough to define homology — the geometry was only ever a way to produce such complexes.
Precisely: a chain complex is a sequence of abelian groups (or modules over a ring) ... -> C_{n+1} -> C_n -> C_{n-1} -> ... together with homomorphisms d_n: C_n -> C_{n-1}, called the differential or boundary maps, satisfying the fundamental identity d_n composed with d_{n+1} = 0 for every n. This identity says the image of d_{n+1} lies inside the kernel of d_n. Elements of ker(d_n) are called cycles, elements of im(d_{n+1}) are called boundaries, and the n-th homology of the complex is the quotient group H_n = ker(d_n) / im(d_{n+1}). Homology measures exactly how far the complex is from being exact at C_n — it is the 'cycles that are not boundaries'.
Why bother with the abstraction? Because the same machinery then runs everywhere: singular and simplicial and cellular chains, the de Rham complex of differential forms, group cohomology, the Koszul complex in algebra, all are chain (or cochain) complexes, and theorems proved once about complexes — the snake lemma, the long exact sequence, chain homotopy invariance — apply to all of them at no extra cost. A chain map between complexes is a family of homomorphisms commuting with the differentials, and it induces maps on homology; this functoriality is what makes the whole edifice computable.
A small but important convention: lowering indices (d decreases degree) gives a chain complex and homology H_n; raising indices (d increases degree) gives a cochain complex and cohomology H^n. They are dual bookkeeping of the same idea, and which you use is a matter of where the arrows point, not a difference in principle.
Take the two-term complex Z -> Z with the map 'multiply by 2', placed in degrees 1 and 0. There d d = 0 holds trivially (nothing else around). Then H_1 = ker(times 2) = 0 and H_0 = Z / im(times 2) = Z/2Z. So homology detects torsion — here the class of 1 in Z/2 is a cycle that is not a boundary in the only sense available.
A two-term complex whose homology Z/2Z shows torsion arising purely algebraically.
The identity d d = 0 is the whole point: without it, ker and im need not nest and the quotient is meaningless. Every 'boundary operator' you meet must be checked to square to zero before homology is even defined.