If one was to look in the Dungeon Master's Guide (DMG) for 5th edition Dungeons & Dragons, there's a section on designing encounters based on player character levels, enemy Challenge Rating (CR), and the number of combatants on either side. On the surface, this seems reasonable. CR is meant to approximate how difficult a given creature would be (insofar as any system can really do that), and the side with the most offensive actions has a noteworthy statistical advantage. However, it doesn't take much thought to see flaws in this approach, flaws which can be overcome by simply putting in some thought and paying attention.
To wit, in what was apparently to be the final combat with the full group of 5 players who I had been running a game for, their characters (all level 2), together with a pair of NPC allies (one a level 3 druid, one a level 0 guard, more on them in a moment), were set to face a group of six gnolls, a horde of lesser demons that they'd summoned (seven manes and three dretches), and their fiendish mutated leader. By the DMG formulae, this encounter would've been "deadly" for 5 level 4 characters or "hard" for 5 level 5 characters, so I must clearly be a power-mad asshole Dungeon Master, right?
Well, let's take a deeper look.
First, the battleground has to be taken into consideration. Formerly the location of a lighthouse on a grassy plain (don't make a "gnoll knoll" joke), the lighthouse was sundered in the process of opening the abyssal portal, leaving a plain with a handful of "boulders" (actually the remains of the lighthouse, but my GIMP skills aren't that good yet), two of which provided areas of full cover/concealment between the starting locations of the two forces. It was also a pretty large map, 40x40 squares (200x200 feet) in total, with something in the area of 25 squares (125 feet) between the characters and all but the foremost lesser demons at the start. Seeing as the party had multiple long range attackers (Tristan the ranger with his longbow, Baz the rogue with his crossbow, and Ta'el the warlock with his eldritch blast), whereas none of the demons and only three or four of the gnolls (depending on how one wanted to count the fiendish gnoll, who delayed a turn in joining to finish his ritual at the portal) had comparable armaments. This meant two things:
1. The players could get in a volley or two before melee engagement, depending on how much they wanted to use their cover vs. getting early shots in.
2. Given that the demons only had 4 square (20 feet) movement speed, they had to use Dash actions to close the distance before getting shredded, so most of the monsters didn't even get to attack on the turn where they engaged in melee.
Second, the starting formations also had to be taken into consideration. The gnolls and demons were quite spread out while the players were in a cluster, so the players were not engaging with the entire enemy force all at once. Further to this, as mentioned above, the leader of the gnolls (who was the only spellcaster on the enemy side) wasn't going to start moving out until its second turn, adding another layer of separation to the enemies. Thus, their numbers advantage wasn't actually as pronounced as a simple count would indicate.
Finally, while gnolls are cunning and vicious, they're also dumb. They used suboptimal tactics, like splitting some of their arrow fire or readying arrows to interrupt healing attempts which they failed to pass an Arcana check to recognize. I'm listing this last because I didn't rely too heavily on it (as, while gnolls are dumb, they're also cunning and vicious), but it was undeniably a factor.
Going into the encounter, I'd been considering giving the portal a chance to spawn more demons at the end of each round after the first one, since that would've been its gimmick if the party that assailed the lighthouse before its destruction. After seeing how the first round went, though, it was obvious that that'd be an annoyance without really being impactful (due to the encounter distance and demon speed notes mentioned above), so I nixed the idea on the spot.
So, how'd it go?
Well, it was a huge battle, so there are still 2 dretches and a gnoll left to be cleaned up, but it played out wonderfully. There was definitely danger, with multiple characters going down to 5 or less HP at various points, but aside from Hugh the level 0 guard, nobody went unconscious. Some dice luck was certainly a factor (Hugh wiped out one manes with a critical to clear a lot of the traffic on their flank, the players failed only one of their four or five saving throws against the fetid clouds of the two dretches who made it into melee, and the fiendish gnoll missed with all three of its ranged spells before getting close enough to light up three characters with a burning hands spell that came close to knocking out two of them, followed by getting a low enough initiative roll on the next round for the party to burst it down before it could do anything more), but all in all, it managed to keep on that razor's edge of disaster that can make D&D combat so fun. That wasn't because I was taking it easy on the players or fudging rolls to make things more dramatic (I'm open with my rolls in combat to make sure the players know that their success or defeat isn't by my whims), but because I did an adequate job of judging the lay of the encounter beforehand and the players did a good job of controlling their characters once the dice hit the table.
And they would've been denied of such a great victory if I'd trusted the DMG over my instincts.
Now, the lesson in this isn't that the encounter building section in the DMG is worthless or that CR has no value. Those things have merit, but they aren't meant to be used dogmatically. They're guidelines, and whatever they recommend has to be tempered by some thought as to their assumptions and limitations. The relative difficulty of shadows or wraiths changed greatly based on what magic weapons or radiant/force-damage sources the party has, for instance, but their CR is etched in laser toner by a group of developers who had to take a guess at such information. The mighty CR 30 tarrasque is a joke if characters can attack it with magic projectiles or save-based spells (like the lowly acid splash) from out of reach (only 23 feet with a jump and tail attack combined) since its reflective carapace was nerfed and it no longer has its great regeneration. On the other hand, puny goblins and kobolds and pixies can be absolutely deadly if supported by the right tricks and traps.
In other words, make use of guidelines, but put in some thought for yourself to make sure those guidelines make sense in your particular situation. That should be obvious design advice, but I see a lot of idiocy get trusted because some computer simulation said it was fine.