Seems like you have a handle on the M4 feedramps situation, so when you say M4 barrel extension, I assume you mean you've seen something like
this for sale.
Most advertised barrels will be sold with the barrel extension already attached. Note that I said "most", though almost all respected vendors will make it clear if a barrel is "stripped" without an extension. Also note a lot of people and some vendors will refer to a barrel that has no front sight base, flash hider, gas tube, upper receiver, or any combination of those, yet still has an installed and indexed extension, as a "stripped" barrel.
They are sold as a separate item because, well, some people have the knowledge and tools to properly assemble a stripped barrel or barrel blank.
Most user level people do not bother with this. From what I understand, since the timing of the threads can and does vary on both the extension and the barrel, the extension is first screwed and properly torqued. The gas port is then drilled to index properly with the indexing pin on the extension. This pin on the extension must be timed properly with the gas port to avoid a cant in the front sight base - excessive windage adjustment or the inability to zero a rifle's windage at all can result. This pin indexes into a notch on the upper receiver for proper alignment in relation to the upper receiver.
Removing an extension from a barrel that has been timed and indexed properly is very bad juju, since to reassemble the the extension and barrel you would have to torque it damned near perfectly. Getting a stripped barrel that has a gas port drilled and no extension is just pure insanity unless you just happen to have a box of extensions to go through until you get one where the threads will time perfectly at the proper amount of torque. Simply put, ta' hell with that.
Below you can see the barrel that has a barrel extension installed at the end (the barrel nut can be seen a bit more towards the middle of the barrel).
Here is the upper receiver in the action block without a barrel installed.
Note how the pin on the extension fits into the groove in the upper receiver.
The barrel nut is then threaded on and torqued to spec. This holds the lip of the extension against the upper receiver, and the pin prevents rotation. Install the weld spring, snap ring, and delta ring (those can be seen off to the side in the first pic) and you get this.
Too long, didn't read: You don't need to buy a separate barrel extension for most barrels. Go
here