I've never developed a game with one (or any game larger than tiny learning projects), so I don't know how much extra dev effort is required to make them happen.
Not that I've ever made one, but my understanding is that it is a decent amount of work to set up, although depending on your build pipeline it may be possible to set it up once (per game) and produce a demo from the current state of the game at any time.
Generally you want your demo to be a restricted slice of the game (possibly the very beginning of it), so you would need to:
1) Code in the prevention of escaping the restricted slice (cut off after time, can't leave an area, progress past a story event).
2) Removal of assets not in the demo slice. This includes both art/audio, but also scripting/code if possible. You want to make sure that enterprising hackers can't discover what flag/bits needs to be flipped to enable your entire game just from the demo, in addition to just reducing download size.
In addition to the basic mechanics of setting up your demo, you would also need to consider what would make the best demo for your game, and maybe even have to build demo specific content that won't show up in the main game, because you need to both introduce players to the game and give them an idea of the main gameplay. The demo for Brutal Legend did a good job introducing players to the game, as it was just the beginning of the game/tutorial, but did a poor job of showing off what the player would be doing for the rest of the game because it didn't show even an inkling of the true strategy game. Releasing a bad demo could even reduce sales of a good game (at least early on when the return on investment tends to be highest).