The postulates of special relativity:
- The Principle of Relativity
The laws of physics are the same in all inertial frames of reference.
- The Constancy of Speed of Light in Vacuum
The speed of light in vacuum has the same value c in all inertial frames of reference.
Note, if one has only the first postulate, one is back in the classical Newtonian frame . The Galilean transformations describe kinematics with vector algebra , where three vectors defined in space $(p_x,p_y,p_z)$ retain their length, which is the scalar(dot) product, in all frames .
The special relativity framework enlarges the dimensions to four by including time with space coordinates , and energy with momentum coordinates, and changing the transformation from Galilean ( where the energy is not entangled with the momentum and time is a parameter), to Lorenz transformations.
Lorenz transformations follow a four vector algebra, with a dot product and they are the mathematical result of the two postulates above.
For the four momentum vectors :
$$
\begin{matrix}
\vec{P_a}=\begin{bmatrix}E_a \\ \vec{p_a}c \end{bmatrix} &
\vec{P_b}=\begin{bmatrix}E_b \\ \vec{p_b}c \end{bmatrix} &
\vec{P_a}\cdot \vec{P_b} = E_aE_b - \vec{p_a}\cdot\vec{p_b}c^2
\end{matrix}
$$
The "length" of this four vector, invariant to Lorenz transformations by construction of the algebra, is the invariant mass squared of the particle characterized by this four vector.
$$\sqrt{P\cdot P}=\sqrt{E^2-(pc)^2}=m_0c^2$$
The length of this 4-vector is the rest energy of the particle. The invariance is associated with the fact that the rest mass is the same in any inertial frame of reference.
This mass is called "invariant mass" and characterizes all elementary particles and the complex additive four vectors of all matter. It can be zero as is seen in the elementary particle table of the standard model of particle physics.
Because of the minus sign in of the contribution of the fourth component to the length of the four vector, in the mathematics of the Lorenz transformations, complex numbers describe the lorenz four vectors simply.
As the other answers state, the E=mc^2, called the relativistic mass, though useful in calculating trajectories with special relativity, is confusing on the basic issues, as it coincides with the invariant mass of systems only in the rest frame. It is a measure of how the inertial mass changes at high velocities, but is not used by particle physicists because of the confusing way it is mentioned in popularization of science. The invariant mass is the concept to use, in the same way one characterizes objects by their constant volume in space even though they may be moving.
See also this answer of mine on a similar question.