So what's the safest and best way to get an encounter right without wiping the party out?
Practice. Start with very easy and increase difficulty as you learn what the party can handle.
Also, if you've got a big battle planned with lots of foes, remember that multiple foes are disproportionately more difficult, especially if they synergize well.
In such situations, I would introduce them in waves, so you can adjust the difficulty of the battle by holding them back (or not) based on how well the PCs are faring.