Let K be an infinite field. There has been recent study of the family H(n, K) of pairs of commuting nilpotent n × n matrices, relating this family to the fibre H [n] of the punctual Hilbert scheme A [n] = Hilb n (A 2 ) over the point np of the symmetric product Sym n (A 2 ), where p is a point of the affine plane A 2 [V. Baranovsky, The variety of pairs of commuting nilpotent matrices is irreducible, Transform. Groups 6 (1) (2001) 3-8; R. Basili, On the irreducibility of commuting varieties of nilpotent matrices, J. Algebra 268 (1) (2003) 56-80; A. Premet, Nilpotent commuting varieties of reductive Lie algebras, Invent. Math. 154 (3) (2003) 653-683]. In this study a pair of commuting nilpotent matrices (A, B) is related to an Artinian algebra K[A, B]. There has also been substantial study of the stratification of the local punctual Hilbert scheme H [n] by the Hilbert function as [J. Briançon, Description de Hilb n C[x, y], Invent. Math. 41 (1) (1977) 45-89], and others. However these studies have been hitherto separate.We first determine the stable partitions: i.e. those for which P itself is the partition Q(P ) of a generic nilpotent element of the centralizer of the Jordan nilpotent matrix J P . We then explore the relation between H(n, K) and its stratification by the Hilbert function of K [A, B]. Suppose that dim K K[A, B] = n, and that K is algebraically closed of characteristic 0 or large enough p. We show that a generic element of the pencil A + λB, λ ∈ K has Jordan partition the maximum partition P (H ) whose diagonal lengths are the Hilbert function H of K [A, B].