A real square matrix is a Z-matrix if it’s off diagonal elements are nonpositive. A Z-matrix with nonnegative principal minors is called an M-matrix. The problem of testing whether a given matrix is an M-matrix or not is an important research problem in matrix theory as M-matrices arise naturally in a wide range of applications including finite difference methods for partial differential equations, input-output models in economics, linear complementarity problems in operations research, and Markov processes in probability and statistics. In this paper, we present a polynomial-time algorithm for testing whether a Z-matrix is an M-matrix based on modified simplex method. © 2021, The Author(s), under exclusive licence to Springer Science+Business Media, LLC, part of Springer Nature.