revix said:
My question is how is it that momentum is conserved if before the shot there was no force in the system and afterwards there was.
What do you mean by "afterwards there was force in the system"? And are you considering the realistic case of a gun that is mounted or held, or the more abstract case of a gun floating free in space?
Let's consider a gun floating in space that fires itself - perhaps a radio controlled trigger. There are only forces on the system for the tiny fraction of a second while the bullet accelerates down the barrel. Before that there are no forces, and after that there are no forces. At all times the gun and the bullet have equal and opposite momenta. Initially they are zero; they grow at equal rates due to the Third Law; when the bullet leaves the barrel they have constant equal and opposite momenta. The total momentum is therefore zero at all times.
Ok so far?
As phinds points out, most guns are either held or mounted, and the analysis depends a bit on how that is treated. A typical way to do it is to treat the Earth, and anything fixed to it, as an immovable object, so its momentum is always zero. This actually leads to a violation of momentum conservation because you are neglecting the momentum of the gun/Earth combination, but as long as you know it's an approximation and the failure of momentum conservation is due to that approximation, that's fine. A more complete way to do it is to consider the Earth as an extension of the gun, and have the Earth recoil slightly when the gun fires. So the gun
is just floating in space because that's what the Earth is doing (you are welcome to work out the recoil speed of the Earth, ##M_E=6\times 1^{24}\mathrm{kg}##, when a 1g bullet is fired at ##300\mathrm{ms^{-1}}##). Of course, when the bullet lands it will give its momentum back to the Earth, so there's no final momentum change in this case.
Hope that makes sense.