TITLE: Why is n mod 0 undefined?
QUESTION [35 upvotes]: I tried to find out what $n$ mod $0$ is, for some $n\in \mathbb{Z}$. Apparently it is an undefined operation - why?

REPLY [3 votes]: Depends on how you define "mod". If you mean "the remainder after dividing", you can't divide by zero, so it's not defined.
However, another way of thinking about mods is as an equivalence relation. We can define it as
$$a \equiv b \pmod{n} \iff n \mid (a-b)$$
where $x \mid y$ means "$x$ divides $y$". In this case, $a \equiv b \pmod{n}$ if and only if $0 \mid (a -b)$, which just means $a = b$.
Lastly, the most general way to think of mods is by using ring theory. Take a ring $R$. An ideal $I$ in $R$ is a subring that is contagious under multiplication, so for all $a \in R$, $x \in I \implies ax \in I$. So for the integers, an ideal might be $I = \{\cdots, -10, -5, 0, 5, 10, \cdots\}$, because if you multiply a multiple of five by something, it's still a multiple of five.
Given a ring and an ideal, we can construct a subring, $R/I$, referred to as "$R$ mod $I$". The elements in this ring are cosets of this ideal. For this example, the coset of $1$ would be $1 + I = \{\cdots, -9, -4, 1, 6, 10, \cdots\}$. Instead of adding and multiplying whole sets, we can pick any representative, and multiplication and addition still end up well-defined. This is modular arithmetic! $1 + 3 \equiv 6 + 3 \equiv -9 + 3 \pmod{5}$, after all.
As for the answer to your question, notice that "the integers mod $n$" is the same as $\mathbb{Z}/n\mathbb{Z}$. So if we let $n = 0$, we mod out by the zero ideal (i.e., $I = \{0\}$), the coset of $a$ would just be $\{a\}$, and we get something isomorphic to $\mathbb{Z}$ again. In other words, $n$ mod $0$ is $n$.