I've always been a bigger guy. Tall and medium build. I used to be a wuss as a kid and teenager and took way more crap than I should have because I certainly didn't need to. It wasn't until my early 20's that I started to get an attitude. It took me years to get the hang of dealing with jerks, and it led to a few scraps which weren't much of a problem and I handled without much issue. I've been there more than a few times to back up some smaller friends who couldn't hold their own at times as well. Now, I hardly take crap from anyone. Unless the dude is a Gorilla, the chick is a psycho, or it's a group of them, then I just leave it be, especially if I'm alone.
You have to be able to judge people well based on their words, facial expressions, body language, etc, but it's not that easy and takes time plus many encounters. Even then you're bound to be wrong sometimes. Truth is the large majority of dickheads are all talk or show and no action. What's important is knowing how to make them feel small without acting like a know it all, but also not dealing with them on their low level. Both those scenario's could very well lead to things getting physical. You also need to be able to deal with the consequences if they do by chance man up, as unlikely as that may be. If you don't know anything about fighting I'd suggest steering clear. The best way to practice is to have other people with you. The bigger the better. Most a-holes won't push the limit if you or the people you're with look like they could be a problem physically. They will typically still shoot their mouth off though, and that gives you a chance to try your hand at getting them to back down.
What to say, how and when, is pretty tough to explain. It depends a lot on the scenario. The best approach I find is to be cocky but witty, and jokey at the same time. You have to at least act like you aren't intimidated and you 'know' they aren't the type to mess around either. You have to be careful not to 'laugh in their face' like you think you're untouchable or to make them feel like a laughing stock, because that can lead to trouble depending on the person. Just standing tall with your head up and shoulder's back even makes a big difference. You don't have to flex, just looking like your not spineless is enough many times to make a serious impression. Watching other people's altercations is a good way to learn, but you really have to pay attention because there's a lot to pick up on.
Whatever you do, don't act soft and don't be a 'nice guy'. They will instantly smell that and you'll just make things worse. Also make sure not to go full douchebag. Two total dickheads typically can only sort things out through getting physical. You want to find the middle ground, and be a smartass jerk basically. You don't really want them to think that you think you can kick their ass, you just want them to think that you know you can hold your own if they try to start sh*t, so they won't bother.
I don't suggest looking for trouble, and if fighting is not an option for you if it occurs, I suggest a punching bag or the gym if you need to get out some spartan rage.
The Canadian National Anthem According To Justin Trudeau