Avoiding The TPK -- NPCs
You did it.
You killed all the PCs.
Your players have crumpled up their character sheets and are arguing over who is to blame for losing the battle. Maybe the Cleric should have healed more often. Maybe the Fighter should have tanked more. Maybe the Wizard should have done a better job handling that swarm of enemies. It all went downhill so quickly. One of your players looks at you accusingly, as though to say, "how could you do this to us?"
The Total Party Kill is a scenario that no gamer wants to face -- well, except, perhaps, for a sadistic DM on a power trip. So what could be done to avoid it?
One technique is to add an NPC or two to the party.
Now, adding an NPC to the party is generally the last approach you want to take, unless you have plot-related reasons for it. But if the party is suffering because it's missing a vital role (Leader, Defender, Striker, Controller), then adding an NPC is something you might want to consider. Newcomers to the game can particularly benefit from an NPC ally, whereas veteran gamers will likely be able to handle things on their own, and may even resent the NPC in the party "stealing their XP and loot."
The most important thing to keep in mind when adding an NPC to the party is your role. You are the DM; you are not a player. You are the narrator of a story that stars the PCs. You are an impartial mediator the players can turn to to settle disputes. You must avoid at all costs the infamous "DM PC," an NPC who the DM favors and treats as his personal character, stealing spotlight from the PCs and eventually being hated by the players.
Your players should be the ones to come up with the plans, make the big decisions, and feel important. NPCs should not take this away from them.
Any NPCs you add to the party should play secondary roles -- sidekicks, minions, bodyguards, employees, hirelings... From a roleplaying standpoint, you could still make the NPC an interesting and complex character who is fun to run, but he should only be there to lend his abilities in battle, not to tell the PCs what to do or solve their problems for them.
If the PCs are Legolas, Gimli, and Aragorn, then there should be no Gandalf NPC in the party. If the PCs are Luke Skywalker and Han Solo, then it's fair to have Chewbacca as an NPC.