M adG raph 5 is the new version of the M adG raph matrix element generator, written in the Python programming language. It implements a number of new, efficient algorithms that provide improved performance and functionality in all aspects of the program. It features a new user interface, several new output formats including C++ process libraries for P ythia 8, and full compatibility with F eynR ules for new physics models implementation, allowing for event generation for any model that can be written in the form of a Lagrangian. M adG raph 5 builds on the same philosophy as the previous versions, and its design allows it to be used as a collaborative platform where theoretical, phenomenological and simulation projects can be developed and then distributed to the high-energy community. We describe the ideas and the most important developments of the code and illustrate its capabilities through a few simple phenomenological examples.