A linear algebra text I'm reading defines Matrix multiplication as $(AB)_{ij}=\sum_{k=1}^nA_{ik}B_{ki}$
Later on in the text they define the trace formula as $tr(AB)=\sum_{i}^n(AB)_{ii}$
What confuses me is that is that since the first formula simply describes a matrix, then based on their notation, doesn't the second describe the sum of all elements? I don't see how it says anything specific about the diagonal. What I get from $(AB)_{ii}$ is that $AB$ is a square matrix, which makes sense since we want the trace. but I still don't see how the second summation formula describes summing the diagonals.