Why does the $2$'s and $1$'s complement subtraction works? The algorithm for $2$'s complement and $1$'s complement subtraction is tad simple:

$1.$ Find the $1$'s or $2$'s complement of the subtrahend.
$2.$ Add it with minuend.
$3.$ If there is no carry then then the answer is in it's complement form  we have take the $1$'s or $2$'s
complement of the result and assign a negative sign to the final
answer.
$4.$ If there is a carry then add it to the result in case of $1$'s complement or neglect in case of $2$'s complement.

This is what I was taught in undergraduate, but I never understood why this method work. More generally why does the radix complement or the diminished radix complement subtraction works? I am more interested in understanding the mathematical reasoning behind this algorithm.

We consider $k$-bit integers with an extra $k+1$ bit, that is associated with the sign. If the "sign-bit" is 0 then we treat this number as usual as a positive number in binary representation. Otherwise this number is negative (details follow).
Let us start with the 2-complement. To compute the  2-complement of an number $x$ we flip the bits, starting after the right most 1.  Here is an example:
 0010100 -> 1101100

We define for every positive number $a$, the inverse element $-a$ as the 2-complement of $a$. When adding two numbers, we will forget the overflow bit (after the sign bit), if an overflow occurs. This addition with the set of defined positive and negative numbers forms a finite Abelian group. Notice that we have only one zero, which is 00000000. The representation 10000000 does not encode a number. To check the group properties, observe that


*

*$a + (-a) = 0$,

*$a+0=a$,

*$-(-a)=a$,

*$(a+b)=(b+a)$,

*$(a+b)+c= a+ (b+c)$.


As a consequence, we can compute with the 2-complement as with integers. To subtract $a$ from $b$ we compute $a+(-b)$. If we want to restore the absolute value of a negative number we have to take its 2-complement (this explains step 3 in the question's algorithm).
Now the 1-complement. This one is more tricky, because we have two distinct zeros (000000 and 111111). I think it is easiest to consider the 1-complement of $a$ as its 2-complement minus 1. Then we can first reduce the 1-complement to the 2-complement and then argue over the 2-complements.
