I'd just approach the problem by induction. There are $2^{n \choose 2}$ possible graphs with $n$ vertices. (Each possible edge either exists or it does not.) How many of them are disconnected?
If there are two vertices, there are $2$ graphs, $1$ disconnected and $1$ connected.
If there are three vertices and the graph isn't connected, there are $4$ distinct possible disconnected components, each of which can exist in only one way. For example, $1-2$ may be one connected component, leaving $3$ to be the other. There are $8$ possible graphs, so $4$ of them are connected.
If there are $4$ vertices, the possible partitions into connected components of disconnected graphs are $\{1, 1, 1, 1\}, \{2, 1, 1 \}, \{2, 2 \}, \text{ and } \{3, 1 \}$. There is $1$ set of $4$ isolated points, there are ${4 \choose 2} = 6$ sets of $2$ isolated points, there are $3$ more sets of $2$ connected components of $2$ points each. Each of those sets of connected components results in exactly $1$ graph each. There also are $4$ sets of $1$ isolated point, each of which (by the previous paragraph) results in $4$ more graphs, for an additional $16$. Therefore, there are $26$ graphs that are not connected. There are $2^{4 \choose 2} = 64$ possible graphs on $4$ vertices, so $38$ of them are connected.
The calculation for $5$ vertices is similar, but a bit more tedious.