Skip to main content
v2026.11,986 entries · CC-BY 4.0

Social Network Analysis: Measures, Worked Example and Code

Learn social network analysis with a fully computed five-node example of density, degree and betweenness centrality, plus reporting and code.

Written and maintained by CASRAI Editorial Board

Published

On this page

Social network analysis (SNA) is a set of methods for studying relationships among actors (people, organisations, papers, countries) by representing them as a graph of nodes and ties and then measuring that structure. After reading this page you should be able to compute density, degree centrality and betweenness centrality by hand on a small network, read the numbers, report them, and reproduce them in Excel, R or Python.

What is social network analysis?

SNA treats the relationship, not the individual attribute, as the unit of analysis. Wasserman and Faust’s standard textbook describes it as an approach focused on relationships among social entities, used across the social and behavioral sciences. In practice you define (1) the actors (nodes), (2) the relation that links them (friendship, advice, co-authorship, citation, trade), and (3) whether ties are directed (A names B) or undirected (A and B co-authored), and whether they carry weights. Every measure below follows from those choices, so they must be stated before any number is reported.

Core measures and their formulas

Network density

Density is the share of possible ties that actually exist. For a simple undirected network, d(G) = 2m / (n(n-1)), where m is the number of observed edges and n the number of nodes (Lizardo & Jilbert, 2023). For a directed network without self-loops the maximum is n(n-1) ties, so d = m / (n(n-1)).

Degree and degree centrality

Degree is the number of edges incident on a node; across an undirected network the degrees sum to 2m. Degree centrality is the fraction of the other nodes a node is connected to, that is, degree divided by n-1 in a simple graph (NetworkX documentation).

Betweenness centrality

Betweenness measures how often a node lies on shortest paths between other pairs: cB(v) = (1/P) Σs,t σ(s,t|v) / σ(s,t), where σ(s,t) is the number of shortest paths from s to t and σ(s,t|v) is how many of them pass through v. By default NetworkX leaves v out when it is s or t. With normalization, the sum is divided by the number of possible (s,t) pairs, N(N-1) for directed and N(N-1)/2 for undirected networks, where N is n when endpoints are included and n-1 otherwise. Without normalization, P = 1.

Worked example: a five-node network

Illustrative hypothetical, not real data. Five actors A to E are linked by five undirected ties: A-B, A-C, B-C, C-D and D-E. So n = 5 and m = 5.

  1. Density: 2 × 5 / (5 × 4) = 10 / 20 = 0.50.
  2. Degrees: A = 2, B = 2, C = 3, D = 2, E = 1. Check: 2+2+3+2+1 = 10 = 2m.
  3. Degree centrality (degree / 4): A = 0.50, B = 0.50, C = 0.75, D = 0.50, E = 0.25.
  4. Betweenness of D (unnormalized): list the pairs that do not include D: AB, AC, AE, BC, BE, CE. Shortest paths through D: A-C-D-E (A to E), B-C-D-E (B to E), C-D-E (C to E). Each is the only shortest path, so each contributes 1. Total = 3.
  5. Betweenness of C (unnormalized): pairs without C: AB, AD, AE, BD, BE, DE. AB and DE are direct ties (0). AD, AE, BD and BE each have a single shortest path through C (1 each). Total = 4.
  6. Normalized: with N = n-1 = 4, the divisor is 4 × 3 / 2 = 6. C = 4/6 = 0.667; D = 3/6 = 0.50. A, B and E lie on no shortest path between others, so their betweenness is 0.

Node C is both the best connected and the main broker; D has few ties but carries the only route to E.

How to interpret the results

Measure Range Reading
Density 0 to 1 0 means no ties; 1 means every possible tie exists. Compare only networks of similar size, because density tends to fall as n grows.
Degree centrality 0 to 1 (normalized) Higher means a node is directly tied to a larger fraction of the network. It says nothing about who those ties connect to.
Betweenness centrality 0 to 1 (normalized) Higher means more shortest paths run through the node, so it can act as a bridge. A node with betweenness 0 can still have many ties (a member of a closed triangle, like A and B above).

In the example, E has the lowest degree centrality (0.25) yet D, its only neighbour, has a betweenness of 0.50: position matters as much as count.

Assumptions and common mistakes

  • Unstated boundary. Results depend on who is included. Say how the node set was drawn (a roster, a sample, a snowball).
  • Missing nodes or ties. Centrality is computed on the observed graph only; omitted actors change every score. This is a data-collection issue that sampling design (see sampling methods) cannot fix after the fact.
  • Mixing directed and undirected conventions. The maximum-ties denominators differ (n(n-1)/2 versus n(n-1)), so software and textbook values can disagree for the same data.
  • Comparing normalized with raw scores. NetworkX normalizes betweenness by default; unnormalized values (such as 4 and 3 above) are counts, not proportions.
  • Treating description as inference. Density and centrality are descriptive (see descriptive versus inferential statistics); ties are not independent observations, so ordinary significance tests on node-level scores are not valid without network-specific methods.

How to report social network analysis (APA)

State the nodes, the relation, whether ties are directed and weighted, the network size, the software and version, and whether centralities are normalized. Example wording (hypothetical figures): “The advice network comprised 5 actors and 5 undirected ties (density = .50). Degree centrality was normalized by n – 1; betweenness was computed with NetworkX (version stated) and normalized.” Cite the method source in text as (Wasserman & Faust, 1994) and in the reference list in APA 7th-edition book format:

Wasserman, S., & Faust, K. (1994). Social network analysis: Methods and applications. Cambridge University Press.

How to calculate it in Excel, R or Python

Python (NetworkX)

import networkx as nx G = nx.Graph([('A','B'),('A','C'),('B','C'),('C','D'),('D','E')]) print(nx.density(G))                                  # 0.5 print(nx.degree_centrality(G))                        # C: 0.75 print(nx.betweenness_centrality(G))                   # C: 0.667, D: 0.5 print(nx.betweenness_centrality(G, normalized=False)) # C: 4.0, D: 3.0

R (igraph)

library(igraph) g = graph_from_literal(A-B, A-C, B-C, C-D, D-E) edge_density(g)                  # 0.5 degree(g)                        # A 2, B 2, C 3, D 2, E 1 betweenness(g, normalized = TRUE)

For the library itself see our igraph guide.

Excel

Enter the network as a symmetric 0/1 adjacency matrix in B2:F6 (row and column labels A to E, zeros on the diagonal). Degree of each node is the row sum, =SUM(B2:F2), filled down. Degree centrality is =G2/(COUNTA($B$1:$F$1)-1). Density for an undirected network is =SUM(B2:F6)/(5*4), since the matrix total counts each tie twice (2m). Betweenness has no built-in Excel function; use R or Python.

Frequently asked questions

What is social network analysis used for?

It is used to describe and compare the structure of relations among actors, across the social and behavioral sciences (Wasserman & Faust, 1994): who is connected, who brokers between groups, and how dense a community is.

What is the difference between degree and betweenness centrality?

Degree counts a node’s direct ties. Betweenness counts how many shortest paths between other pairs pass through the node. In the example, A has degree centrality 0.50 but betweenness 0.

Why do different programs give different centrality values?

Mostly because of normalization and directedness. Raw counts and normalized proportions use different denominators, as set out above and in the NetworkX documentation.

Is SNA a quantitative or qualitative method?

The measures here are quantitative, but the choice of actors and relation is a design decision made on conceptual grounds, and qualitative work can also use network ideas.

Sources

  • Wasserman, S., & Faust, K. (1994). Social network analysis: Methods and applications. Cambridge University Press. cambridge.org/9780521387071 (read 2026-11-08).
  • Lizardo, O., & Jilbert, I. (2023). Social networks: An open textbook, lesson on graph metrics. olizardo.github.io/networks-textbook/lesson-graphs-metrics.html (read 2026-11-08).
  • NetworkX documentation: betweenness_centrality and degree_centrality. networkx.org/documentation/stable/ (read 2026-11-08).

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Social Network Analysis: Measures, Worked Example and Code

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →