Atiyah MacDonald Commutative algebra page 3 On page 3 of Atiyah and MacDonald's Commutative algebra book, the following is written.
If $f\colon A\to B$ is a ring homomorphism and $q$ is a prime ideal in $B$, then $f^{-1}(q)$ is a prime ideal in $A$, for $A/f^{-1}(q)$ is isomorphic to a sub-ring of $B/q$ and hence has no zero divisor not equal to zero. But if $n$ is a maximal ideal it is not necessarily true that $f^{-1}(n)$ is maximal in $A$; all we can say for sure is that it is prime.
Why is $A/f^{-1}(q)$ isomorphic to a sub-ring of $B/q$? I intuitively get it, but what's the formal argument? Also, why can't I argue similarly for maximal ideals? What is there in the prime ideal case that does not work in the maximal ideal case? I am aware there is a counter-example but I don't quite understand the essence  of it. Can someone help?
 A: Let $\pi\colon B\to B/q$ be the quotient map $\pi(b) = b+q$. We have $\ker(\pi) = q$. 
Now let's consider the composition $\pi\circ f\colon A\to B/q$. If we can show that $\ker(\pi\circ f) = f^{-1}(q)$, then the ring isomorphism theorem gives $A/f^{-1}(q)\cong \text{im}(\pi\circ f)\subseteq B/q$.  
Certainly if $a\in f^{-1}(q)$, $f(a)\in q$, so $\pi(f(a)) = f(a)+q = 0+q$, and $f^{-1}(q)\subseteq \ker(\pi\circ f)$. Conversely, if $\pi(f(a)) = 0+q$, then $f(a) \in \ker(\pi) = q$, so $a\in f^{-1}(q)$. So $\ker(\pi\circ f) = f^{-1}(q)$, as desired. 

Regarding maximal ideals: What we've shown above is that when $q$ is prime,  $A/f^{-1}(q)$ is isomorphic to a subring of the integral domain $B/q$, so it's an integral domain. In the case that $q$ is maximal, $A/f^{-1}(q)$ is isomorphic to a subring of the field $B/q$. 
But not every subring of a field is a field. The easiest example is $\mathbb{Z}\subseteq \mathbb{Q}$. 
And that suggests a simple counterexample to the proposition that the preimage of a maximal ideal is maximal. Let $f\colon \mathbb{Z}\to \mathbb{Q}$ be the inclusion, and let $q = (0)\subseteq \mathbb{Q}$. $q$ is a maximal ideal in $\mathbb{Q}$, but $f^{-1}(q) = (0)\subseteq \mathbb{Z}$ is not a maximal ideal in $\mathbb{Z}$. 
A: $A/f^{-1}(q)$ is isomorphic to a sub-ring of $B/q$ because there exists an injective ring homomorphism,
$\phi : A/f^{-1}(q)\to B/q$ 
$a$ mod $f^{-1}(q)\to f(a)$ mod $q$.
Can you verify that it is well defined injective ring homomorphism?
