Disclaimer - a lot of technical information is taken from this thread: https://forums.beamdog.com/discussion/comme...Comment_1020831
Math
So, when a fight happens, the combat log is full of messages like that:
CODE
Char: Attacks Enemy
Char: Attack Roll 7 + 7 = 14 : Hit (or Miss)
Char: Attack Roll 7 + 7 = 14 : Hit (or Miss)
The basic formula for what we see is the following:
CODE
(1d20 roll) + (luck + modifiers) = (result)
Luck is a cumulative sum of values from spells like Luck and Chant and effects of Fatigue or Intoxication. Modifiers is a sum of anything explicit or hidden that might affect the Char's to-hit value and the Enemy's AC bonuses vs. specific weapons (there are some other factors such as Invisibility, but they are less important). Please refer to the linked thread for a complete list of luck factors and modifiers.
Once this value is calculated, and the 1d20 roll was not a critical hit (always hits) or miss (always misses), the engine does the following check:
CODE
(result) >= (Base THAC0 - Target AC)
Here, Base THAC0 is a sum of everything that affects the base THAC0 of the Char directly. Similarly, Target AC is everything that modifies the base AC of the Enemy (including armor class set by an equipped armor or a spell, Dexterity and some other stuff). Complete lists are provided in the same linked thread.
To demonstrate better how all of it works, let's look at a specific example. Let's say we have a character who reached her base AC cap of -24 and has no extra bonuses to AC against specific damage types. She is being attacked by a Golem-type enemy with a base THAC0 of -6, Strength value of 25 (which gives a 7 bonus to hit) and a -5 to-hit bonus on its blunt weapon. There aren't any luck factors involved. For those curious, these are the stats of a Greater Elemental Golem.
The formula would look like that:
CODE
1d20 + 0 (no luck factors) + 7 (modifier from high strength)
Now the resulting value is inserted into the second formula:
CODE
1d20 + 7 >= (-6 [base THAC0] + (-5) [to-hit bonus of the weapon]) - (-24) [character's base AC]
1d20 + 7 >= 13
1d20 + 7 >= 13
As you can see, despite the fact that our character has reached the base AC cap, the golem will hit on any roll greater than or equal 6.
There is a bit of confusion on which sign is to use for the various modifiers and luck factors involved in the first formula due to the general weirdness of D&D 2.5. Based on intuition and numerous tests, I think that all factors that benefit the attacker go with the "plus" sign and those benefitting the attacked go with the "minus" sign.
For the next example, let's imagine that we equip the maximum possible amount of AC vs. blunt damage (20 points) on our character. Let's look at the first formula again:
CODE
1d20 + 0 (no luck factors) + 7 (modifier from high strengh) - 20 (the newly added AC vs. blunt) = 1d20 - 13
And we insert it into the second formula again:
CODE
1d20 - 13 >= 13
Now, the only way the golem can hit our character is when it rolls a natural d20 (a critical hit). Quite a difference!
Takeaways
All this math is quite cumbersome and, obviously, we cannot be expected to work it out in our heads for every hit in every fight. So instead, let's list a few important notes on how AC stacking works in the game.
1. The total character's AC is a sum of two parts: base AC and AC vs. specific damage type. First, the game sums together all bonuses to the base AC until the value hits the cap for that particular character. Once the base AC is calculated, all AC modifiers vs. specific damage type are added on top.
2. Any bonus to AC that is not specifically mentioned to be against a certain damage type, is being added to the base AC value. This includes the majority of items and spells.
3. The AC value you see on the character's inventory screen is the base AC (the enhanced edition also provides a useful breakdown of how it is calculated).
4. The cap for the base AC depends on a character's dexterity. The lowest (i.e., best) possible value is -26 with the Dexterity score of 25. See detailed breakdown table here: https://baldursgate.fandom.com/wiki/Dexterity
5. The maximum possible value for AC bonus vs. specific damage type is 20. This cap cannot be modified.
6. AC bonuses against a specific damage type are not listed on the inventory screen. However, you can see the accumulated values on the character info screen (Information tab, scroll down until you see "Armor Class Modifiers"). Here, the negative values make total AC better, the positive ones - make it worse.
7. All items, spells and abilities that give an AC bonus vs. specific damage type, will say so explicitly in their description. Somewhat counter-intuitively, the descriptions might say something like "+4 against crushing". This will always mean a positive bonus (i.e., the engine will treat it as -4 for the purpose of calculation). For examples, see Girdle of Bluntness.
8. Some armors have additional positive or negative bonuses to AC vs. specific damage type. They are sometimes unlisted (which is a lapse on our part), but you can always see the cumulative value on the character screen.
For example, Pride of the Legion +4 explicitly says that it provides "Armor Class: -1 (-5 vs. slashing, -4 vs. piercing and missile)". This means that it gives extra -4 vs. slashing and -3 vs. piercing and missile on top of base AC of -1.
Another useful example is Chain Mail +1. Its description says "Armor Class: 4 (2 vs. slashing, 6 vs. crushing)". This means that it will give an extra -2 bonus vs. slashing on top of base value of 4, but against crushing it will actually offset the base value with a negative bonus of 2 (meaning that the enemies will have a better chance to hit your character with blunt weapons).
Conclusion
So, what does this all mean? If you want to have a character that tanks effectively well into late game, you should aim for AC values beyond -30. The theoretical maximum AC value vs. a specific damage type can reach -46 with 25 Dexterity. Although I am not sure if it's possible to hit this cap on practice, it's quite feasible to have a buffed character with AC somewhere between -30 and -40. That means maximising base AC, getting 25 Dexterity and stacking as much AC vs. specific type as possible on top, with the help of items, spells (including very specific buffs such as the Shaman's spell Entropy Shield) and employing things like Swashbuckler's on-hit melee ability Mirrored Blade (which is the reason why Swashbuckler is mentioned as a high tier class in late game by experienced players).
Hope that helps! Feel free to add comments, examples and corrections.