Measuring Graph Density and What It Predicts About a Network
9 min read · updated August 11, 2026
Density is the ratio of the edges a graph has to the edges it could have. It is one division, it is reported constantly, and on a large network it mostly tells you how large the network is rather than anything about its structure.
The formula, worked
For a simple undirected graph with n nodes and m edges, the maximum possible edge count is every unordered pair, n(n−1)/2. Density is the fraction of those that exist:
density = 2m / (n (n - 1)) undirected, no self-loops density = m / (n (n - 1)) directed, no self-loops worked example: an internal collaboration network n = 1,200 people m = 8,400 collaboration edges max possible edges = 1200 x 1199 / 2 = 719,400 density = 8,400 / 719,400 = 0.011676 -> 1.17% average degree = 2m / n = 16,800 / 1,200 = 14
So 1.17% of the possible edges exist, and the average person has 14 collaborators. Those are the same fact stated twice, and the second statement is the one a human can act on. Hold that thought — it is the whole argument of this page.
Why it collapses as the graph grows
Rewrite density in terms of the average degree k = 2m/n. Substituting gives density = k / (n - 1). Density is therefore average degree divided by size, and if the average degree stays put while the graph grows, density falls as 1/n. Take the same network at three scales with each person still keeping 14 collaborators:
n m density
1,200 8,400 1.1676%
12,000 84,000 0.1167%
120,000 840,000 0.0117%
1,200,000 8,400,000 0.0012%Nothing about how people collaborate changed across those rows. The density fell by a factor of a thousand. This is why comparing the density of a 5,000-node graph with a 5,000,000-node one tells you essentially nothing: real networks are sparse, average degree grows slowly at most, and density is dominated by the denominator.
Report average degree, the degree distribution, and the clustering coefficient instead. Average degree is size-independent. The degree distribution says whether the graph is regular or hub-dominated, which two graphs of identical density can differ on completely. The clustering coefficient — the fraction of a node’s neighbour pairs that are themselves connected — captures local density in a way that does not shrink with n.
What it does predict: path length
Density is not useless; it is useful through average degree. In a random graph on n nodes with average degree k, the number of nodes reachable within d hops grows roughly as k^d, so the typical distance between two nodes is about the d that makes k^d reach n:
expected path length ~ ln(n) / ln(k) n = 1,200, k = 14 -> ln(1200) / ln(14) = 7.090 / 2.639 = 2.69 hops n = 1,200,000, k = 14 -> ln(1.2e6) / ln(14) = 14.00 / 2.639 = 5.30 hops
A thousandfold increase in size adds about two and a half hops. That is the small-world result, and it explains something people find counter-intuitive about very sparse graphs: 0.0012% density still puts everyone within about five steps of everyone else. It also has a hard practical consequence for graph machine learning, because the receptive field of an L-layer GNN is the L-hop neighbourhood. At k = 14, three layers reach roughly 14³ = 2,744 nodes and five layers reach 537,824 — nearly half the million-node graph. Beyond the typical path length, every node’s receptive field is the whole graph and every node’s representation is built from the same inputs, which is one way of stating oversmoothing.
The other threshold worth knowing is the connectivity one. In the Erdős–Rényi random graph model, a giant connected component containing a constant fraction of all nodes appears exactly when the average degree passes 1. Below that the graph is a scatter of small fragments; above it, one component swallows most of the nodes. If your constructed graph is fragmenting, average degree near 1 is the first thing to check, and the usual cause is a filter applied during construction rather than anything about the underlying data.
Where density is genuinely useful
The measure earns its place when it is applied to a subgraph and compared with the ambient rate. A set of 40 accounts with 600 edges among them has density 2 × 600 / (40 × 39) = 0.769, against a graph-wide density of perhaps 0.00001. That ratio is enormous, it is not explained by size, and it is the signal underneath dense-subgraph fraud detection — see graph-based anomaly detection for transaction networks. Community detection algorithms are doing a version of the same comparison: a good community is a node set whose internal density exceeds what its degree sequence would produce by chance.
Local density also drives cost. A graph library’s neighbour sampling, its adjacency layout and its memory footprint are all functions of degree, so a densely connected region is where the expensive batches come from even when the global density is negligible.
One more legitimate use is as a sanity check on a graph you just built. Density that is exactly 1 usually means every pair got an edge from a join that lost its condition. Density that jumps by an order of magnitude between two extraction runs means the filter changed, not the world. Neither reading tells you anything about network structure, but both catch a pipeline bug in one number, and a bug caught before training is worth more than a metric that describes the graph accurately after it.
Four ways the number lies
- Bipartite graphs cannot reach 1. With two sides of sizes a and b, the only possible edges are the a × b crossing pairs. For a = b = n/2 the maximum density under the standard formula is about 0.5, so a perfectly complete bipartite graph reports as half empty. Compare against a × b, not n(n−1)/2, whenever the graph is user-to-item, author-to-paper or account-to-merchant.
- Multigraphs can exceed 1. Transaction and call-record graphs have parallel edges. Density above 1 is not a bug in the code; it means the denominator assumed a simple graph. Either collapse parallel edges into a weight first or report average edge multiplicity separately.
- Directed graphs have two conventions. Some libraries divide by n(n−1) and some by n(n−1)/2, giving answers a factor of two apart. Two teams reporting “density” for the same directed graph and disagreeing by exactly 2× have found this, not a data problem. Check the definition before comparing.
- Isolated nodes are in the denominator. Any node with zero edges lowers density without changing structure, so a construction that emits every entity in a source table — including the ones that never appear in a relationship — reports a lower density than the same graph after pruning. Say whether isolates are included, because it changes the number and nothing else.