The notion of ideal comes from a generalization of modular arithmetic. It is a refinement (by Dedekind) of Kummer's notion of ideal number, which arose from attempts to prove Fermat's Last Theorem (or some special cases).
When you have a number $n\in {\bf Z}$, then the multiples of $n$ form an ideal in ${\bf Z}$ (a principal ideal denoted by $(n)$ or $n{\bf Z}$). The ring ${\bf Z}_n$ of integers modulo $n$ is then actually the quotient ring ${\bf Z}/n{\bf Z}$. If $p$ is prime, then $p{\bf Z}$ is a prime (even maximal) ideal and ${\bf Z}_p={\bf Z}/p{\bf Z}$ is a domain (even a field).
Similarly, if you have any ring $R$ and an ideal $I\unlhd R$, then $R/I$ makes sense and has a natural ring structure, which is a domain iff $I$ is prime and a field iff $I$ is maximal.
For Dedekind domains, there is a further analogy: if $R$ is a Dedekind domain (for example, the integer subring of a number field), then any nonzero ideal $I\unlhd R$ factors uniquely into a product of prime ideals and nonzero prime ideals are exactly the maximal ideals.
In ${\bf Z}$, this corresponds to the fact that any natural number decomposes uniquely into a product of prime numbers (as ${\bf Z}$ is a principal ideal domain, every ideal is principal).