Balancing encounters is difficult. To create challenge that is both difficult yet surmountable is no easy task, and regardless of how thoroughly you read the DMG, this article, or pretty much any other source, the only way to get good at it is through practice. That being said, here are some of the more important elements to watch out for when it comes to balancing a combat encounter.
But first, a free homebrewed monster stat block:
1. Action Economy
Far and away, number of actions on each side of a combat is the most important part. A small party is going to struggle with enemies that have multiattack or groups with more enemies than a large party. Similarly, a large party can often beat a much stronger enemy than they should be able to simply by swarming them, forcing them to either retreat, take opportunity attacks, or suck up a huge number of blows. When there's a big party, it also means PCs going down isn't as scary, because there are more people to stabilize them while others can maintain damage output. The bigger the party, the stronger the enemy force has to be.
2. CR and Level
The CR system has its flaws, the biggest of which (in my opinion) is the number of encounters it assumes the party will go through. The DMG states "most adventuring parties can handle six to eight medium to hard encounters in a day." - pg. 84. This means, between long rests, the CR rules are built around this huge number of encounters. Most players don't want to be fighting that often, and fighting that often as a DM can get exhausting. So, assuming your party is level 3 or higher (if they're 1 or 2 a higher CR monster might oneshot them), it's a safe bet that you can increase the CR of whatever creature they're fighting by at least two. This isn't universal, and in general you'll have to edit how strong your enemies can be in cumulative CR as the campaign goes, but if you're throwing enemies that are the same CR as your party's level, they'll be able to take on 6-8 of those type of encounters before it gets tough.
3. Party Composition
The biggest thing to watch out for in party composition is magic vs martial. If you're lacking in magical members, the combat difficulty will naturally increase as the party levels up because casters scale harder than martial classes (in general). The other thing to watch out for is ranged attacks. If a party is weaker at range than it is up close, or vice versa, then you can use that either to your advantage or theirs. For example, you can throw some weaker enemies at them like goblins, but give the enemies some space and let them harass the party that struggles to deal high damage at range. On the other hand, if there are a lot of range-based PCs, having enemies get up in their face to cause disadvantage on attacks, that's equal frustrating. Then to flip it, use the party's strength at range to allow them to take down a strong CR enemy and make them feel strong. Casters and range, keep an eye out.
4. Magic Items
Magic items are fun, they make your party love you when you give them out, and sometimes they are encounter breaking. Whether it's because a monster happens to be susceptible to the items damage, because the item allows for some kind of communication that would otherwise not be possible, or simply because magic items allow for every party member to deal magic damage, negating the slashing, bludgeoning and piercing resistance. However you slice it, parties tend to be keen to utilize their magic items in the most extreme and unexpected ways possible. Watch for number and strength of magic items when building an encounter, and doubly so if those items are strong or specific.
The most often forgotten, and biggest difference between great encounter and mediocre encounter, is the environment. The place which combat occurs is fully in the DM's hands, and hiding unknown hazards, shaping the terrain to play to a monster, and drawing player attention to something that doesn't even matter are excellent ways to spice up encounters. What's cooler: fighting in a sand pit, or on a thin bridge spanning a bottomless pit? Fighting in a the forest or fighting in the forest during a windstorm with trees falling all about? The environment need not always be dangerous, but combat and everything about it is always inherently dangerous, so the players should never feel comfortable once initiative is rolled. The beauty of playing around with various environments is that the environment is equal. It may be good for the enemy, it may be good for the party. The reason the environment is so good for balancing an encounter is that you, the DM, know exactly what there is in the area, how the enemies can utilize it, and what to avoid. The PCs come in with less info. Whenever possible, make the environment interesting.
Using these five elements of an encounter, the ways in which you can balance combat may become more clear. This is obviously not a roadmap for how to create perfect encounters, but hopefully it can provide some clarity as to why some encounters work great and some do not. This is of course also not an exhaustive list, and many factors contribute to a successful encounter. Whatever it is that makes combat fun, keep an eye on your encounters and never be afraid to try new stuff, edit every elements, and lean into what works. And, as always, don't forget to have fun.