Updated:

1. Give any spawn egg

/give @s minecraft:zombie_spawn_egg
/give @s minecraft:allay_spawn_egg 16

The item ID is the mob name plus _spawn_egg. The last number is the count. Bedrock uses the same IDs.

2. Eggs you cannot get in survival

MobItem ID
Ender dragonender_dragon_spawn_egg
Witherwither_spawn_egg
Iron golemiron_golem_spawn_egg
Snow golemsnow_golem_spawn_egg

Java added these in 1.19.3. A dragon from an egg may just hover in place outside the End. For a real fight, see the ender dragon command.

3. Named or NoAI eggs (Java)

/give @s minecraft:villager_spawn_egg[entity_data={id:"minecraft:villager",CustomName:"Mayor",NoAI:1b,PersistenceRequired:1b}]

This egg spawns a frozen villager named Mayor. Put the same data you would use with /summon inside entity_data, and always include id.

/give @s minecraft:zombie_spawn_egg[entity_data={id:"minecraft:zombie",IsBaby:1b}]

In 1.21.4 and earlier, write the name as CustomName:'"Mayor"'. In 1.20.4 and earlier, use {EntityTag:{...}} instead of the component.

4. Change a spawner

Right-click a spawner with a spawn egg in creative to change its mob. For the command method, see the spawner command.

Troubleshooting

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.