Some spaces come in one piece and some come in several. "One piece" sounds obvious until you try to define it with nothing but open sets. The answer is to define the opposite: a space falls apart if it can be split into two open pieces. This is the idea behind the Intermediate Value Theorem, and it's the first real tool for proving two spaces are not homeomorphic.
A space falls apart when it splits into two open pieces that don't overlap.
Let $X$ be a topological space. A separation of $X$ is a pair $U, V$ of disjoint nonempty open subsets of $X$ whose union is $X$.
Connected means "no way to do that."
The space $X$ is connected if there does not exist a separation of $X$.
A direct consequence: if $U, V$ is a separation, then $U = X \setminus V$ is both open and closed. So a space is connected if and only if the only subsets of $X$ that are both open and closed are $\emptyset$ and $X$ itself.
On the Closed Sets page, $[0, 1]$ was both open and closed inside $Y = [0, 1] \cup (2, 3)$. That was a separation of $Y$ hiding in plain sight.
Which of these are connected: a set with the trivial topology, a set with at least two points and the discrete topology, and $\mathbb{Q}$ as a subspace of $\mathbb{R}$?
Trivial topology: connected. The only open sets are $\emptyset$ and $X$, so there's no room for two disjoint nonempty ones.
Discrete with two or more points: not connected. Pick a point $p$; then $\{p\}$ and $X \setminus \{p\}$ are open, disjoint, nonempty, and cover $X$.
$\mathbb{Q}$: not connected. $\mathbb{Q} \cap (-\infty, \sqrt{2})$ and $\mathbb{Q} \cap (\sqrt{2}, \infty)$ are open in $\mathbb{Q}$, disjoint, nonempty, and their union is $\mathbb{Q}$ (since $\sqrt{2} \notin \mathbb{Q}$).
For subspaces, there's a way to spot separations using limit points, without mentioning open sets at all.
If $Y$ is a subspace of $X$, a separation of $Y$ is a pair of disjoint nonempty sets $A$ and $B$ whose union is $Y$, neither of which contains a limit point of the other. The space $Y$ is connected if there exists no such separation.
Proof. Suppose $A$ and $B$ form a separation of $Y$ (in the open-set sense). Then $A$ is both open and closed in $Y$. The closure of $A$ in $Y$ is $\overline{A} \cap Y$ (closed sets of $Y$ are closed sets of $X$ intersected with $Y$), and since $A$ is closed in $Y$, $A = \overline{A} \cap Y$. So $\overline{A} \cap B = \emptyset$. Since $\overline{A} = A \cup A'$, $B$ contains no limit points of $A$. Swapping the roles of $A$ and $B$, $A$ contains no limit points of $B$.
Conversely, suppose $A$ and $B$ are disjoint nonempty sets whose union is $Y$, neither containing a limit point of the other. Then $\overline{A} \cap B = \emptyset$ and $A \cap \overline{B} = \emptyset$. So $\overline{A} \cap Y = A$ and $\overline{B} \cap Y = B$, which means $A$ and $B$ are both closed in $Y$. Since $A = Y \setminus B$ and $B = Y \setminus A$, they are both open in $Y$ as well, so they form a separation. $\blacksquare$
That's a very practical test on the real line: two pieces of $Y$ can be split apart unless one of them contains a point that the other crowds up against. Try it.
$[0, 1) \cup (1, 2]$ and $[0, 1) \cup [1, 2]$ differ by one point, and that one point decides everything. When a subspace of $\mathbb{R}$ is a union of intervals, look at each place two pieces meet and ask: is the meeting point in the space?
The key lemma: a connected subspace can't be split by a separation of the big space. It has to land entirely on one side.
If the sets $U$ and $V$ form a separation of $X$, and if $Y$ is a connected subspace of $X$, then $Y$ lies entirely within either $U$ or $V$.
Proof. Since $U$ and $V$ are open in $X$, the sets $U \cap Y$ and $V \cap Y$ are open in $Y$. They are disjoint and their union is $Y$. If both were nonempty, they would form a separation of $Y$. So one is empty, and $Y$ is contained in the other. $\blacksquare$
Everything else in this section follows from that lemma. First, connected sets that share a point glue together.
The union of a collection of connected subspaces of $X$ that have a point in common is connected.
Proof. Let $\{A_\alpha\}$ be a collection of connected subspaces with $p \in \bigcap A_\alpha$, and suppose $\bigcup A_\alpha = U \cup V$ is a separation. Without loss of generality $p \in U$. Each $A_\alpha$ is connected, so it lies entirely in $U$ or in $V$, and it can't lie in $V$ because it contains $p \in U$. So every $A_\alpha \subset U$, hence $\bigcup A_\alpha \subset U$, contradicting that $V$ is nonempty. $\blacksquare$
Second, adding limit points can't disconnect a set.
Let $A$ be a connected subspace of $X$. If $A \subset B \subset \overline{A}$, then $B$ is also connected.
Proof. Suppose $U, V$ is a separation of $B$. By the lemma, $A$ lies entirely in $U$ or in $V$; say $A \subset U$. Then $\overline{A} \subset \overline{U}$. By the limit-point form of a separation, $\overline{U}$ and $V$ are disjoint, so $B \cap V \subset \overline{A} \cap V \subset \overline{U} \cap V = \emptyset$. That contradicts $V$ being nonempty. $\blacksquare$
Third, and most important: continuous maps preserve connectedness.
The image of a connected space under a continuous map is connected.
Proof. Let $f: X \to Y$ be continuous with $X$ connected, and let $Z = f(X)$. Restricting the range gives a continuous surjection $g: X \to Z$, so it's enough to show $Z$ is connected. Suppose $U, V$ is a separation of $Z$. Then $g^{-1}(U)$ and $g^{-1}(V)$ are disjoint and their union is $X$. They are open because $g$ is continuous, and nonempty because $g$ is surjective. So they form a separation of $X$, contradicting that $X$ is connected. $\blacksquare$
So a continuous function can crush a connected space, stretch it, fold it, and wrap it around itself a hundred times, but it can never tear it. Continuous functions are the world's most careful movers.
We still need one connected space to start from. The real line works because it has no gaps, which is captured by an order-theoretic definition. (A set has the least upper bound property if every nonempty subset that is bounded above has a least upper bound.)
A simply ordered set $A$ having more than one element is a linear continuum if the following hold:
$\mathbb{R}$ is a linear continuum. $\mathbb{Q}$ is not (it fails the least upper bound property: think of $\{q : q^2 < 2\}$), and $\mathbb{Z}$ is not (nothing between $1$ and $2$).
The real line $\mathbb{R}$ is connected, and so are the intervals and rays in $\mathbb{R}$.
Proof. We prove the unit interval $[0, 1]$ is connected; the other cases follow the same way (or from the theorems above). Suppose $U, V$ is a separation of $[0, 1]$, and say $1 \in V$. Let $s = \sup U$ (which exists since $U$ is nonempty and bounded). $U = [0, 1] \setminus V$ is closed in $[0, 1]$, so it contains its supremum: $s \in U$. Since $1 \in V$, $s < 1$. But $U$ is also open in $[0, 1]$, so some interval $[s, s + \varepsilon)$ lies in $U$, which gives points of $U$ bigger than $s = \sup U$. Contradiction. So $[0, 1]$ is connected. $\blacksquare$
For $\mathbb{R}$ itself: $\mathbb{R} = \bigcup_{n} [-n, n]$, a union of connected sets (each is homeomorphic to $[0, 1]$) sharing the point $0$, so it is connected by the union theorem.
Put "continuous images are connected" together with "intervals are connected," and out comes the Intermediate Value Theorem, in a far more general form than calculus ever gave it.
Let $f: X \to Y$ be a continuous map, where $X$ is a connected space and $Y$ is an ordered set in the order topology. If $a$ and $b$ are two points of $X$ and $r$ is a point of $Y$ lying between $f(a)$ and $f(b)$, then there exists a point $c \in X$ such that $f(c) = r$.
Proof. Consider the sets $$A = f(X) \cap (-\infty, r) \quad \text{and} \quad B = f(X) \cap (r, \infty).$$ They are disjoint, and nonempty because one contains $f(a)$ and the other contains $f(b)$. Each is open in $f(X)$, being the intersection of $f(X)$ with an open ray. If no $c \in X$ had $f(c) = r$, then $f(X) = A \cup B$, and $A, B$ would form a separation of $f(X)$. But $f(X)$ is connected, as the continuous image of a connected space. So such a $c$ exists. $\blacksquare$
Drag the level $r$ for a connected domain and a disconnected one.
In calculus the IVT was about $f: [a, b] \to \mathbb{R}$. Here, the domain is any connected space, and the only thing the proof needed from $[a, b]$ was that it's connected.
There's a more hands-on version of "one piece": you can walk from any point to any other.
Given points $x$ and $y$ in a space $X$, a path in $X$ from $x$ to $y$ is a continuous map $f: [a, b] \to X$ of some closed interval in the real line into $X$, such that $f(a) = x$ and $f(b) = y$.
A space where every pair of points has a path between them gets its own name.
A space $X$ is called path connected if every pair of points of $X$ can be joined by a path in $X$.
For example, $\mathbb{R}^n$ is path connected (use straight lines), and so is $\mathbb{R}^2 \setminus \{0\}$ (go around the hole if you have to). Path connected spaces are always connected (Exercise 6).
The converse fails. The "topologist's sine curve," the graph of $\sin(1/x)$ for $0 < x \le 1$ together with the segment $\{0\} \times [-1, 1]$, is connected (it's the closure of a connected set) but not path connected: no path can travel from the segment to the wiggly part. So when a problem says "connected," don't assume you can draw paths.
One more definition, at the opposite extreme from connected.
A space is totally disconnected if its only connected subspaces are one-point sets.
First, a surprise about the finite complement topology.
Show that if $X$ is an infinite set, then it is connected in the finite complement topology.
Proof. Suppose $U, V$ is a separation of $X$. Since $U$ and $V$ are nonempty and open in the finite complement topology, $X \setminus U$ and $X \setminus V$ are finite. But $U$ and $V$ are disjoint with union $X$, so $X \setminus U = V$ and $X \setminus V = U$. Then $X = U \cup V$ is a union of two finite sets, so $X$ is finite, a contradiction. $\blacksquare$
Next, the two directions between "discrete" and "totally disconnected."
Show that if $X$ has the discrete topology, then $X$ is totally disconnected.
Proof. Let $A \subset X$ contain at least two points, and choose $p \in A$. Every subset of $X$ is open, so $\{p\}$ and $A \setminus \{p\}$ are open in $A$; they are disjoint, nonempty, and their union is $A$. So $A$ is not connected. The only connected subspaces are one-point sets (and $\emptyset$). $\blacksquare$
And the converse.
If $X$ is totally disconnected, does $X$ have the discrete topology?
No. $\mathbb{Q}$, with the subspace topology from $\mathbb{R}$, is totally disconnected: any subset $A$ containing two rationals $p < q$ is separated by an irrational $s$ between them, via $A \cap (-\infty, s)$ and $A \cap (s, \infty)$. But $\mathbb{Q}$ is not discrete: $\{0\}$ is not open in $\mathbb{Q}$, since every interval around $0$ contains other rationals.
Compare the next one with the Hausdorff version.
Let $X$ be a topological space and $A, B \subset X$ be closed subsets of $X$ such that $X = A \cup B$. If $A$ and $B$ are connected, is $X$ connected?
Not necessarily. Let $A = [0, 1]$, $B = [3, 4]$, and $X = A \cup B$ with the subspace topology from $\mathbb{R}$. Then $A$ and $B$ are closed in $X$ and connected, but the open sets $X \cap (-1, 2)$ and $X \cap (2, 5)$ form a separation of $X$. (If $A \cap B \neq \emptyset$, though, the union theorem says $X$ is connected.)
On the Hausdorff page, the same setup (two closed pieces) did pass the property up to $X$. Connectedness is different: it's about how the pieces fit together, and closed pieces can sit far apart.
The last one is the classic application of connectedness to path connected spaces.
Prove that if $X$ is path connected, then $X$ is connected.
Proof. Suppose $X$ is path connected but not connected. Then there is a separation $U, V$ of $X$. Choose $x \in U$ and $y \in V$, and a path $f: [a, b] \to X$ from $x$ to $y$. Then $f^{-1}(U)$ and $f^{-1}(V)$ are open in $[a, b]$ (by continuity), disjoint, nonempty ($a \in f^{-1}(U)$ and $b \in f^{-1}(V)$), and their union is $[a, b]$. That is a separation of $[a, b]$, which contradicts the connectedness of intervals. So $X$ is connected. $\blacksquare$
Here's the payoff: connectedness can tell spaces apart.
Show that $\mathbb{R}$ and $\mathbb{R}^2$, both with their standard topologies, are not homeomorphic.
Proof. Suppose $f: \mathbb{R} \to \mathbb{R}^2$ is a homeomorphism. Pick any $p \in \mathbb{R}$. Restricting $f$ gives a bijection $$g: \mathbb{R} \setminus \{p\} \to \mathbb{R}^2 \setminus \{f(p)\},$$ and $g$ and $g^{-1}$ are continuous (restrictions of continuous maps), so $g$ is a homeomorphism. But $\mathbb{R}^2 \setminus \{f(p)\}$ is path connected (any two points can be joined by a straight segment, or by two segments that go around $f(p)$), hence connected. And $\mathbb{R} \setminus \{p\}$ is not connected: $(-\infty, p)$ and $(p, \infty)$ form a separation. Homeomorphisms preserve connectedness (the image of a connected space under the continuous map $g^{-1}$ is connected), so this is impossible. Hence no homeomorphism exists. $\blacksquare$