Live-ball fouls by both teams, regardless of associated penalty distances, will offset. Keep in mind that fouls offset, not penalties. So, just know that an offside by B is offset by a hold by A; or a hold by A is offset by a facemask by B; or an illegal formation by A is offset by a roughing the passer by B; etc. Also, if both teams foul, with one team (or both) having multiple fouls, they all offset.
The exception to this is the "clean hands" privilege. If one team is free from foul before last gaining possession, then they commit a foul after last gaining possession, they can keep the ball by declining offsetting fouls, and thus, declining the penalty for the opponent's foul. Then, the opponent has the option to accept or decline the penalty by the team in possession.