Let F be a field, and let M n ( F) be the algebra of n× n matrices over F. Let A, B ∈ M n ( F) with AB = BA, and let A be the algebra generated by A, B over F. A theorem of Gerstenhaber [ Ann. Math. 73:324–348 (1991)] states that the dimension of A is at most n. Gerstenhaber's proof uses the methods of algebraic geometry. In this paper, we obtain a purely matrix-theoretic proof of the result. We also examine the case when equality occurs. The case where F is algebraically closed and A is indecomposable (under similarity) holds the key to the general situation, and in the indecomposable case, we obtain a Cayley-Hamilton-like theorem expressing B k as a polynomial in I, B,…, B k−1 with coefficients in F[ A], where k denotes the number of blocks in the Jordan form of A. If all Jordan blocks of A have the same size, we obtain a nonderogatory-like condition on B which is equivalent to dim F A = n . We also show that in this case dim F A = n is equivalent to the maximality of A as a commutative subalgebra of M n ( F).