Every time you send a WhatsApp message, stream a video or pay a bill online, a remarkable amount of mathematics runs silently in the background. Numbers decide how your data is written, which path it takes across the world, how errors are caught and how it is kept secret from eavesdroppers. Here is a guided tour of the maths behind the internet, with calculations you can do yourself.
Everything Is Binary
Computers store and send information using only two symbols, 0 and 1, called bits. A group of 8 bits is a byte. Each position in a binary number is a power of 2, just as each position in a decimal number is a power of 10. For example:
$$ 1011\,0010_2 = 128 + 32 + 16 + 2 = 178 $$
With \(n\) bits you can make \(2^n\) different patterns. One byte gives \(2^8 = 256\) patterns, enough for every letter, digit and punctuation mark in basic English text. Urdu, Arabic and emoji characters use the Unicode standard, which needs two to four bytes per character.
Addresses: Counting With Powers of Two
Every device on the internet needs an address, like a postal address for data. The original system, IPv4, uses 32-bit addresses, usually written as four bytes such as 192.168.1.10. The number of possible addresses is:
$$ 2^{32} = 4{,}294{,}967{,}296 $$
About 4.3 billion sounded enormous in 1981, but with billions of phones, laptops and smart devices, the world ran short. The newer IPv6 uses 128-bit addresses:
$$ 2^{128} \approx 3.4 \times 10^{38} $$
That is enough to give every grain of sand on Earth trillions of addresses of its own. A simple change in an exponent solved a global shortage.
Packets and Speed
Large files are not sent in one piece. They are chopped into small packets, usually around 1,500 bytes each, which travel independently and are reassembled at the destination. If one packet is lost, only that packet is re-sent.
Internet speeds are measured in megabits per second (Mbps), while file sizes are measured in bytes. Students often forget the factor of 8.
Worked Example 1: Download Time
How long does it take to download a 1.5 GB video on a 50 Mbps connection? (Use 1 GB = 1000 MB.)
Step 1: Convert gigabytes to megabytes.
$$ 1.5\ \text{GB} = 1.5 \times 1000 = 1500\ \text{MB} $$
Step 2: Convert megabytes to megabits (1 byte = 8 bits).
$$ 1500\ \text{MB} \times 8 = 12{,}000\ \text{Mb} $$
Step 3: Divide by the speed.
$$ t = \frac{12{,}000\ \text{Mb}}{50\ \text{Mb/s}} = 240\ \text{s} = 4\ \text{minutes} $$
Sanity check: in practice it takes a little longer, because each packet carries extra header information and networks are rarely at full speed. A real figure of 4 to 5 minutes is typical, so our answer is sensible.
Finding the Best Route: Graph Theory
The internet is a giant graph: routers are points (vertices) and cables are lines (edges), each labelled with a cost such as delay in milliseconds. Routers constantly solve a shortest-path problem, often using an algorithm published by Dutch computer scientist Edsger Dijkstra in 1959.
Consider five routers with these delays (in ms): A–B 4, A–C 2, B–C 1, B–D 5, C–D 8, C–E 10, D–E 2. What is the fastest route from A to E?
Dijkstra's method works outward from the start, always fixing the closest unfinished router:
- Start at A (distance 0). Neighbours: B = 4, C = 2.
- The closest unfixed router is C (2). Through C: B = 2 + 1 = 3 (better than 4), D = 2 + 8 = 10, E = 2 + 10 = 12.
- Next closest is B (3). Through B: D = 3 + 5 = 8 (better than 10).
- Next closest is D (8). Through D: E = 8 + 2 = 10 (better than 12).
- Finally E is fixed at 10.
The best route is A → C → B → D → E with total delay 10 ms, even though it passes through four links while the "direct-looking" route A → C → E (12 ms) uses only two. Routing protocols such as OSPF run this calculation in real time inside routers across the world.
Catching Errors
Signals get corrupted by electrical noise, so a 0 might arrive as a 1. The simplest protection is a parity bit: add one extra bit so that the total number of 1s is even. If 1011001 (four 1s) is sent as 10110010, the receiver counts the 1s; an odd count reveals an error. More powerful methods, such as cyclic redundancy checks (CRC), treat the bits as a polynomial and divide by a fixed polynomial, sending the remainder along with the data. If the receiver's remainder does not match, the packet is re-sent.
Keeping Secrets: RSA Encryption
When you see the padlock in your browser, your connection is encrypted. One of the most famous systems is RSA, published in 1977 by Ron Rivest, Adi Shamir and Leonard Adleman. Its security rests on a simple fact: multiplying two large prime numbers is easy, but splitting their product back into primes is extraordinarily hard.
Worked Example 2: RSA With Small Numbers
Real RSA uses primes hundreds of digits long, but the steps are identical with small ones.
Step 1: Choose two primes. \(p = 3\), \(q = 11\).
Step 2: Compute the modulus. \(n = p \times q = 33\).
Step 3: Compute Euler's totient.
$$ \varphi(n) = (p-1)(q-1) = 2 \times 10 = 20 $$
Step 4: Choose a public exponent \(e\) sharing no factor with 20. Take \(e = 3\). The public key is \((e, n) = (3, 33)\).
Step 5: Find the private exponent \(d\) with \(e \times d \equiv 1 \pmod{20}\). Since \(3 \times 7 = 21 = 20 + 1\), we get \(d = 7\). The private key is \((7, 33)\).
Step 6: Encrypt the message \(m = 4\):
$$ c = m^e \bmod n = 4^3 \bmod 33 = 64 \bmod 33 = 31 $$
The eavesdropper sees only 31.
Step 7: Decrypt using \(c^d \bmod n = 31^7 \bmod 33\). Work in small pieces:
$$ 31^2 = 961 = 29 \times 33 + 4 \;\Rightarrow\; 31^2 \equiv 4 $$
$$ 31^4 \equiv 4^2 = 16 $$
$$ 31^7 = 31^4 \times 31^2 \times 31 \equiv 16 \times 4 \times 31 = 1984 = 60 \times 33 + 4 \equiv 4 $$
We recover \(m = 4\), the original message. Anyone can encrypt with the public key, but only the holder of \(d\) can decrypt, and finding \(d\) requires factorising \(n\). For a 2048-bit \(n\), no known classical computer method can do this in any practical time.
Did You Know?
- The first message sent over ARPANET, the ancestor of the internet, in 1969 was meant to be "LOGIN", but the system crashed after "LO".
- Google's original PageRank algorithm, which ranked web pages, is based on finding an eigenvector of a gigantic matrix.
- Data compression formats such as ZIP rely on counting how often symbols appear and giving frequent ones shorter codes, an idea known as Huffman coding (1952).
Key Takeaways
- All internet data is stored and sent in binary; \(n\) bits give \(2^n\) possibilities.
- IPv4 offers \(2^{32}\) addresses, while IPv6 offers \(2^{128}\), solving the address shortage.
- Remember the factor of 8 when converting file sizes in bytes to speeds in bits per second.
- Routers use graph algorithms such as Dijkstra's to find the shortest path for data.
- RSA encryption relies on modular arithmetic and the difficulty of factorising large numbers.
Working on modular arithmetic, graph theory or computer networks assignments? Amathify's experts and PhD scholars offer step-by-step solutions and assignment help; reach us on WhatsApp or use the Ask a Question form.
Stuck on a problem or assignment?
Our experts and PhD scholars solve maths, physics and chemistry — step by step.