Here's the basic answer to your question about the XM177 vs M4/M4A1.:
The XM177 is essentially a later variant of the Car 15 (aka Colt Commando). The Car 15 was the first shortened version of the M16, made durring vietnam, and originally had a 10 inch barrel. With such a short barrel, it proved to have gigantic muzzel flash and piss-poor accuracy, so they fitted it with a special flash hider which brought the total barrel length to 11.5 inches, which solved much of its problems.
The M4 was made durring the 90's and has a 14 inch barrel. This may not seem like much of a difference, but relatively speaking it is much longer than the Car 15 barrel. If you look at 2 pictures side by side you will notice the difference. The barrel of the Car 15 ends almost immediately at the end of the hand gaurd. On the M4, the barrel is still not extremely long, but it still extends far past the hand gaurd.
By the way, if you were wondering, the M16 has a 22 inch barrel.
I'm no expert, and I probably missed a lot of detailed, but this should help you get the general idea.