Design your encounter areas with terrain that a smart group could use as chokepoints or strategic positions, such as a high platform where a ranged character could be fairly safe while the defender guards the ramp leading to it.
And then give your PCs a chance to use said terrain
before you move your monsters into it.
Neglecting such can quickly result in requests for new character sheets, especially at low levels.
Generally, as
eamon said, the XP budget is [standard monster xp] times [# PCs]. In this case, you're looking at about 4200 xp of challenges for an equal level encounter. Higher levels are doable but get even swingier when you've only got 3 PCs. Suddenly, the economy of actions is much against them and they start dropping, fast.
Encounter challenge comes down to action economy. Which side has the largest number of
effective actions per round? That's the side that will win.
So 40 level N-8 minions lose because they need an 18+ to cause damage, thus having Zero effective actions per round. 4 level N+1 monsters will be really tough since they generally have as many effective actions per round as the 3 PCs. 3 level N+5 monsters will probably win because almost all their actions are effective and only one-third of PC actions will be effective.
*Effective, in this context, is an action that can be reliably used (natural 13 or less) to either cause harm to the opposition (attacks) or increase that side's ability to cause harm to the opposition (healing, buffs, moving to flank, etc.).
Good luck and have fun.