The key property: (a + b) mod m = ((a mod m) + (b mod m)) mod m. You can take mod before or after addition and get the same answer. This property is what makes modular arithmetic work in programming.
Example: (23 + 19) mod 5. Direct way: 42 mod 5 = 2. Modular way: (23 mod 5) + (19 mod 5) = 3 + 4 = 7, then 7 mod 5 = 2. Same result, but the modular way keeps numbers smaller.
Why does this matter? If a and b are huge, a + b might overflow. But (a mod m) and (b mod m) stay small, so you can add them safely. This prevents integer overflow bugs in your code.