No matter how many times you tear apart a lego toy and rebuild it, the number of blocks you are using stays constant. This obvious, intuitive principle is the foundation for the law of conservation of mass, which dictates that no matter how how many times atoms are split up and rearranged, there will always be the same number of them, and they will always have the same mass.
This idea was first developed by Antoine Lavoisier, an 18th Century French chemist, who introduced an innovation to experiments on the mass of reactants before and after reactions. Unlike previous chemists, who had burned substances like wood and observed that their mass decreased, Lavoisier cleverly added the notion of a closed system, or one from which matter cannot escape. He burnt his wood in a bell jar, and found that the total mass of the bell jar did not decrease.
Of course, like all ideas from classical physics, the idea that matter could not be created or destroyed was turned on its head by the Theory of Relativity. Relativity postulates that energy and matter are effectively interchangeable, meaning that a system can lose mass - as long as its energy increases in accordance with e=mc^2. Relativity also dictates that energy and mass are not absolute. Instead, they are simply the products of a frame of reference (i.e. the motion of an observer with respect to the object being observed).
This leads Relativity to establish a new law of conservation of mass: Within a system observed from an unchanging frame of reference, the sum of total energy and mc^2 will remain constant throughout time.
If you think Relativity is weird, just wait for Quantum Mechanics. quantum Mechanics dictates, among other things, that it is impossible to know with absolute precision the total mass or energy of a system. Quantum Mechanics also dictates that a system can spontaneously gain or lose any amount of energy or mass, so long as the gained energy is eventually lost again, and the lost energy is eventually gained again. Bizarrely, the energy need not come from anywhere. It just appears.
Fortunately for our sanity, Quantum and Relativistic effects are almost never observable on Earth, at human scales. For all intents and purposes outside of nuclear labs, matter cannot be created or destroyed, meaning that the total amount of matter in a system will be constant throughout time.