A monster spawner spawns monsters.
To spawn mobs, the player needs to be very close to the spawner. It can spawn mobs in dark spaces up to two blocks to the left, three blocks to the right, four blocks above, and five underneath (see the picture below). However, the mob may be partially outside this area when it spawns, because skeletons and zombies are two blocks tall and spiders are two blocks wide. It can spawn mobs on any solid block within the spawning area, if the area is not obstructed by solid blocks. Skeletons and zombies require a 1 by 2 space to spawn, and spiders require a 2 by 1 space to spawn. They are not kept from spawning by non-solid blocks, such as water and backdrops. If the whole spawn area is obstructed by solid blocks, mobs will not spawn.
Every 10 seconds or so, the spawner tries to spawn a mob. It will not spawn a mob if another mob spawned by the spawner is still alive, no matter how far away it goes. This is to prevent lag and dungeons and spawner rooms becoming too difficult to raid.
If the monsters were killed instantly, the monster spawner could have a 1 in 160 chance of spawning a monster every second.
It is possible for the player to use mob spawner mechanics to their advantage and use it to kill mobs to collect their drops and experience.
For maximum efficiency, the player should kill the mobs as quickly as possible, so that the next mob can spawn. Having more spawning space doesn't seem to speed up spawning, so it is better to have a small area in which they can spawn, so that the player can kill the mob quickly without having to move themselves or the mob.
To make it dark, the player can build the farm underground (or high up in the sky) or use odd torches, which create darkness.