Definition
Arithmetic expansion is the bash facility that evaluates an integer expression inside a $(( ... )) construct and substitutes the resulting numeric value back into the surrounding command line. It supports the standard C-style operators — addition, subtraction, multiplication, integer division, modulo, exponentiation, bitwise and logical operators, and the full family of comparison operators — and it treats bare identifiers inside the construct as variable references without requiring a leading dollar sign.
Arithmetic expansion is one of several expansion mechanisms the shell performs before executing a command, alongside parameter expansion, command substitution, brace expansion, pathname expansion, and tilde expansion. Its job is narrow and well-defined: turn a numeric expression into a number.
Why it matters
How it works
When bash encounters $(( expression )), it tokenises the expression, resolves variable references, evaluates the operators with their normal precedence, and replaces the entire construct with the resulting integer. Because the evaluation happens inside the shell process, there is no fork-and-exec cost — which is why arithmetic expansion is dramatically faster than calling expr in a loop. The legacy expr utility still works and remains useful in strictly POSIX environments where $(( ... )) cannot be assumed.
The major limit is precision: arithmetic expansion handles signed integers only and silently truncates division. For any work that needs fractional results — currency, statistics, percentages with decimals — pipe through bc with the -l flag, which loads the math library and switches to arbitrary-precision arithmetic. The division of labour is clean: $(( ... )) for fast integer counters and conditional checks inside scripts; bc for occasional precision work where speed does not matter.