The law of conservation of momentum states that for two objects colliding in an isolated system, the total momentum before and after the collision is equal. This is because the momentum lost by one object is equal to the momentum gained by the other.
Conservation of momentum is derived from Newton's laws of motion. Newton's third law states that every action has an equal but opposite reaction; the force that one object A exerts on object B is equal but opposite to the force that object B exerts on object A. By Newton's second law, this force is equal to the product of the mass and the acceleration of the objects, so the product of the mass and acceleration of object A is equal but opposite to the product between the mass and acceleration of object B.
Acceleration is the change of velocity divided by the time. Time is cancelled in the equation because in a collision, the forces act within the same time frame. Thus, the product of object A's mass and change in velocity is equal but opposite to the product of object B's mass and change in velocity. Momentum is defined as the product of mass and velocity, so finally the change in object A's momentum is equal to the opposite of the change in object B's momentum. In a nonisolated system, an external force is applied during the collision, changing the original equation and causing momentum to differ before and after the collision.