I have a feeling the RAW will suggest that this work just like with any single entity (like a goblin), but affecting a swarm seems like it should not simply be an "all or nothing" consideration. While trying to divvy up the swarm into individual units would be absurd, the description of the swarm already lists a "half-strength" variant. What do people think of an interpretation (or perhaps house rule) that allows you to put half of them to sleep and force them to therefore do half-damage until the other half is awoken? I suppose the complication would be that you would now have to track each individual half's own hit points, which certainly isn't ideal. Anyone have any other ideas beyond what the standard might suggest?
RAW, sleep does not affect a swarm.
In the description of the Sleep spell, PHB p.276:
Undead and creatures immune to being Charmed aren't affected by this spell.
All swarms in the Monster Manual (p.337-339) are immune to many conditions that typically would target a single or a fixed number of creatures: charmed, frightened, grappled, paralyzed, petrified, prone, restrained, or stunned. By this interpretation, the spell should not affect any swarms.
If a player were looking to homebrew this to have an effect on a swarm however, they may look at the individual creatures stat block and consider the swarm as an appropriately sized group of the creatures.
As an example, let's take the Swarm of Rats (MM p. 339). This swarm has a standard 24 hit points total, and an individual rat (MM p.335) has a standard 1 hit point. This would seem to imply there are 24 rats in a swarm, and from that we could say the sleep spell could target the swarm, and affect those rats as separate individuals, putting to sleep each individual rat up to the full hit points of the swarm, or however many hit points were rolled with the spell cast.
This would result in potentially creating two swarms however, as the still awake rats would continue there attack, and 1 minute later the affected rats would wake up together, creating a second swarm.