If I have a
Graph, how can I count how many disconnected pieces it has? Mathematica must know this since it is able to separate them out when it displays the graph, but I can't find any function which gives the number.
The usual term is connected components.
You can use
Length@WeaklyConnectedComponents[graph]. This will work on directed graphs as well, assuming that you are looking for the components of the underlying undirected graph.
IGraph/M also has a fast function for measuring the sizes of connected components without actually returning them:
Shortly after posting this I found that I can use
to get the desired number.