$M$ is a compact manifold with boundary $N$,then $M$ can't retract onto $N$.

There is hint: Prove $H^{n-1}(N) \to H^{n-1}(M)$ is trivial. Just don't know how to prove this.


So that we're not worried about orientability, I will work with $\mathbb Z_2$ coefficients. Also, I will assume that $M$ and $\partial M$ is connected. (If $\partial M$ is not connected, $H_{n-1}(\partial M)\to H_{n-1}(M)$ isn't necessarily $0$.) If you look at the long exact sequence of the pair $(M,\partial M)$, you discover that $H_{n-1}(\partial M;\mathbb Z_2)\to H_{n-1}(M;\mathbb Z_2)$ is $0$ if and only if the boundary map $$H_{n}(M,\partial M;\mathbb Z_2)\to H_{n-1}(\partial M;\mathbb Z_2)$$ is surjective. Well by Lefschetz duality $H_{n}(M,\partial M;\mathbb Z_2)\cong H^0(M)=\mathbb Z_2$. Similarly by Poincare duality $H_{n-1}(\partial M;\mathbb Z_2)\cong H^0(\partial M;\mathbb Z_2)=\mathbb Z_2$. In the long exact sequence, since $H_n(M;\mathbb Z_2)=0$, the boundary homomorphism is injective, implying that it is surjective since the codomain is $\mathbb Z_2$.

If you assume that your manifolds can be triangulated, then this is easy to see geometrically. The fundamental class of $H_{n-1}(\partial M;\mathbb Z_2)$ is the sum of simplices in the triangulation, which is the boundary of the sum of the simplices in $M$, implying that the inclusion $\partial M\to M$ is trivial in $n-1$-dimensional homology. This works for most manifolds, but unfortunately there are manifolds which cannot be triangulated, so you need the more subtle Poincare duality argument.


To improve on Cheerful Parsnips's answer, we can relax to the assumptions to the case that only $M$ is connected. This will imply that no compact $n$-manifold with boundary can retract to its boundary because a retraction of a disconnected manifold with boundary would induce a retraction of some component onto its boundary.

Assume the existence of a retraction $r: M \rightarrow \partial M$. Consider the following portion of the long exact sequence of the pair $(M,\partial M)$:

$H_n(M; \mathbb{Z}_2) \xrightarrow[]{j_{*}} H_{n}(M,\partial M; \mathbb{Z}_2) \xrightarrow[]{\partial} H_{n-1}(\partial M; \mathbb{Z}_2 \xrightarrow[]{i_{*}} H_{n-1}(M;\mathbb{Z}_2)$.

Since $M$ is compact and $\mathbb{Z}_2$-orientable, and because $(M,\partial M)$ is a good pair (a collar neighborhood deformation retracts onto $\partial M$) Lefschetz duality gives

$H_{n}(M;\mathbb{Z}_2)\approx H^{0}(M,\partial M; \mathbb{Z}_2)\approx \tilde{H}^{0}(M/\partial M; \mathbb{Z}_2)=0$.

On the other hand, again by Lefschetz duality

$H_{n}(M,\partial M; \mathbb{Z}_2) \approx H^{0}(M;\mathbb{Z}_2) \approx \mathbb{Z}_{2}$.

Using this we conclude using exactness that $\partial$ is injective. Combining this with the fact that $i_*$ is injective (because a retraction exists), we have $\mathbb{Z}_2 \approx \text{Im}~ \partial = \text{ker}~ i_*$ which is a contradiction.