Here's what I've been trying, and it seems to work out ok, although I am only a few sessions in:
First, balance the encounter considering only the player characters. Then for each allied monster, add a same-CR monster to the other side. So, if you have a CR2 monster as an ally, the opposing side gets a CR2 monster added in.
Otherwise, it's very hard to do the math because the CR of a monster doesn't translate very well to its "level" as a character.
You should scale the encounters to increase the difficulty for your party.
The ability to scale encounters to your party is very important when you do not intend on following a campaign to the T. The DMG actually clarifies how to do this for your party on page 82. Where it tells you how to gauge your party's difficulty rating by XP values. Within this section of the book, you can adjust the encounters appropriately.
The way to do this by the book is to gauge the combined XP difficulty of your party:
XP Thresholds by Character Level
\begin{array}{l|llll}
\text{Level} & \text{Easy} & \text{Medium} & \text{Hard} & \text{Deadly} \\ \hline
\vdots & \vdots & \vdots & \vdots & \vdots \\
7 & 350 & 750 & 1100 & 1700 \\
\vdots & \vdots & \vdots & \vdots & \vdots \\
\end{array}
If you have seven players who are level 7, the XP Thresholds By Character Level table specifies:
A Hard encounter for that party would have a threshold of 1100XP * 7 players = 7,700 XP.
A Deadly encounter, by this table, would have over 1700XP * 7 players = 11,900 XP.
When creating the encounter, gauge how many creatures it has, and use the XP from their statblocks in the monster manual (or elsewhere) to determine if they meet this threshold. In this case, let's try using ochre jellies as a test creature for this encounter (though a harder encounter would have more variable creatures than just one type).
The Ochre Jelly has CR2 (450XP). The table on p. 82 of the DMG specifies that you do the following to gauge encounters:
- Add up the XP values of all the monsters in the encounter.
- Multiply that XP value to determine its challenge based on the Encounter Multipliers table on the same page (82).
- Compare it to the party's XP challenge value calculated earlier (7,700, hard / 11,900 deadly) to gauge difficulty.
- The highest threshold that that combined XP value surpasses indicates its difficulty.
So normally 7 Ochre Jellies would only be 3150 XP. But with the creature quantity multiplier, 7-10 monsters is 2.5X. Bringing that XP total to 7875. This would constitute a Hard encounter by the reasoning within the DMG.
\begin{array}{ll}
\text{Number of Monsters} & \text{Multiplier} \\ \hline
1 & \times 1\\
2 & \times 1.5\\
3\text{–}6 & \times 2\\
7\text{–}10 & \times 2.5\\
11\text{–}14 & \times 3\\
15+ & \times 4\\
\end{array}
Ultimately, it is your job as a DM to scale up the encounters if the party has improved beyond what the campaign has originally stated. This is a tool provided by WoTC to help DMs determine how to cater to custom campaigns and/or premade campaigns that are adjusted.
I personally find that Deadly level encounters are the only way to give my players a run for their money. Anything below it can be made trivial pretty easily.
Best Answer
An "encounter" isn't necessarily "battle". There are multiple ways to succeed in an encounter, and often are the non-combat ways the most flavorful. One can also combine different approaches with battle to place themselves into an advantageous position. In this scenario, you should balance the encounter for the way you wish it to be resolved.
If you want your PC's to jump into the fray and take both groups on, you'll make it so that having all enemies fight the PC's exclusively would be on the high end of Hard, or the low end of Deadly. As the fight progresses, you have your PC's targeted depending on how much attention they're drawing. You throw in some NPC on NPC combat to adjust the difficulty whenever the fight starts going really bad for the players. You don't have to strictly simulate that combat. Instead just say "During this round, the first side lost X people while the second side lost Y people. The others that aren't attacking you are still in a furious battle.", or "As you're about to be killed, your enemy gets distracted by a sword swinging towards his head from his side. He instead turns to defend."
If you want your PC's to take an alternative course of action, you should make the encounter dip well into Deadly (again balancing for the case that all NPC's would attack only the players). This would discourage making themselves targets of all the available enemies. The players could instead try to just sneak past the fight, stealthily thin down both sides (reducing their numbers) before entering the fray, or ally themselves with one side. They could even attempt peace negotiations, in which case they would likely be ignored, unless a few enemies from either side break off from the main fight to get rid of the nuisances. Or they can just wait in the shadows until one side wins, and then execute the remainder. The encounter that results from a smart choice doesn't even have to be Hard. Intelligence itself should be rewarded.
Either way you choose to balance the encounter, make sure to determine different XP rewards based on the results. The different results possible are: avoid fight, help the weaker side, help the stronger side, or kill all. Make sure that, in the case of helping one side win, they get some extra XP for the tactical decisions made and the Charisma checks needed to establish the alliance. You would add that to the count of dead bodies on the other side. Keep in mind that allying with the stronger side might be harder for your players to do as that side has slightly less incentive to comply. For the losing side, a simple "don't kill us and we'll help you" could suffice.
In the case the players wait for one side to lose before they jump in, just decide what a regular two-sided encounter would be, and say that's how many enemies survived. You can design the new encounter before the session the same way that you would make any other simple two-sided encounter. Throw in some extra XP for doing the smart thing if you want.