If math was a long time ago

Many people in IT have not done any math since school, and some remember it mainly as something they were bad at. If that is you, you are in good company, and you are better prepared than you think: if you have ever worked out how long a download will take, split a bill or checked whether a disk will be full by Friday, you have done the kind of math this topic is about.

School math is often taught as a set of tricks to memorize for a test. In IT it works the other way round: you start with a practical question ("how many hosts fit in this subnet?", "how much downtime does 99.9% allow?") and use math as a tool to answer it. The tool is usually small. And unlike at school, you always have a calculator: Python, which is free and checks your work exactly.

Every page in this topic is built the same way:

  1. The idea first, in plain words, often with a picture.
  2. A worked example with every step written out, including the steps that textbooks call "obvious".
  3. The general rule, now that you have seen it work.
  4. Where it is used in IT, with links to the pages that use it.
  5. Python examples that you can run to check every calculation yourself.

You can read the pages in order, or jump straight to the one you need: each page explains its own terms and links back to earlier pages where it builds on them.

Where math shows up in IT

Math is not a separate subject in IT; it is hidden inside everyday tasks. The table below connects common tasks to the math behind them, to the page in this topic that explains that math, and to the page elsewhere on this site where the task itself is explained.

IT task Math behind it Math page Where it is used
Subnetting an IPv4 network Powers of 2, binary numbers Powers, roots and logarithms, Number bases Subnetting formulas
Reading disk and file sizes Metric and binary prefixes, powers of 10 and of 2 Units, prefixes and data sizes Counting capacity
Usable space in a RAID set, rebuilding a lost disk Multiplication, XOR parity Binary arithmetic and bitwise operations RAID 5
Uptime targets and redundancy Percentages, probability Probability Series and parallel availability
Response times, "p95 latency" Mean, median, percentiles Statistics for IT SLA, SLO and SLI
Judging how code scales with more data Logarithms, growth rates Sequences, sums and growth rates Big O notation
Encryption, certificates and signatures Primes, remainders (modular arithmetic) The math behind cryptography Asymmetric encryption
Search by meaning, training AI models Vectors, derivatives Vectors and matrices, Derivatives Cosine similarity, Gradient descent
Detecting damaged data in transit or storage XOR, remainders, polynomials Error detection and correction Parity in RAID
Money amounts that must add up to the cent Rounding, how computers store fractions Floating-point numbers Floating point

Notice what is not in the table: there is no task that needs you to prove theorems or to do long calculations by hand. What IT asks of you is to recognize the kind of problem, set it up correctly, and check the answer.

Three worked examples

To show what "a little math" looks like in practice, here are three questions that come up at Kestrel Energy, a fictional Dutch energy supplier used throughout this site. Each one is answered with one short formula.

How many devices fit in a subnet?

Tomasz Nowak, a network engineer, needs a subnet for 50 smart-meter gateways in the documentation range 198.51.100.0. Is a /26 big enough? An IPv4 address has 32 bits. The prefix length (here 26) says how many bits belong to the network; the remaining bits number the hosts. Two addresses in every subnet are reserved (the network address and the broadcast address), so:

\text{usable hosts} = 2^{32 - p} - 2
  1. Fill in the prefix: p = 26, so the exponent is 32 - 26 = 6.
  2. Compute the power: 2^6 means 2 × 2 × 2 × 2 × 2 × 2 = 64 addresses.
  3. Subtract the two reserved addresses: 64 − 2 = 62 hosts.
  4. 62 is at least 50, so a /26 is big enough.
# Usable host addresses in an IPv4 subnet: 2^(32 - prefix) - 2
for prefix in (24, 26, 30):
    hosts = 2 ** (32 - prefix) - 2
    print(f"/{prefix}: {hosts} hosts")
/24: 254 hosts
/26: 62 hosts
/30: 2 hosts

Python writes "to the power" as **. The subnetting page explains the networking side, including the exceptions for /31 and /32.

How much space does a RAID 5 set give?

A storage server has 6 disks of 8 TB in RAID 5. RAID 5 spreads parity information over all disks, which costs the space of one disk. With n disks of size s:

\text{usable} = (n - 1) \cdot s
  1. Work inside the brackets first: n - 1 = 6 − 1 = 5.
  2. Multiply: 5 × 8 TB = 40 TB usable, out of 6 × 8 = 48 TB raw.
# RAID 5 usable capacity: (n - 1) x disk size
disks, size_tb = 6, 8
print(f"Raw: {disks * size_tb} TB, usable: {(disks - 1) * size_tb} TB")
Raw: 48 TB, usable: 40 TB

The dot \cdot means "times"; see the notation table below. Why the parity costs exactly one disk is explained on the RAID page.

How much downtime does a chain allow?

Kestrel's customer portal needs both the web servers (available 99.9% of the time) and the database (99.95%). If either one is down, the portal is down. When two independent parts must both work, you multiply their availabilities, written as decimals:

  1. Convert the percentages: 99.9% = 0.999 and 99.95% = 0.9995.
  2. Multiply: 0.999 × 0.9995 = 0.9985005, about 99.85%.
  3. The rest is downtime: 1 − 0.9985005 = 0.0014995, about 0.15% of the time.
  4. A 30-day month has 30 × 24 × 60 = 43,200 minutes; 0.0014995 × 43,200 ≈ 64.8 minutes of downtime.
# Two services in a chain: both must be up
portal = 0.999      # 99.9%
database = 0.9995   # 99.95%
both = portal * database
print(f"Availability of the chain: {both:.2%}")
minutes = 30 * 24 * 60
print(f"Downtime budget in 30 days: {(1 - both) * minutes:.1f} minutes")
Availability of the chain: 99.85%
Downtime budget in 30 days: 64.8 minutes

The chain is less available than either part on its own, which surprises many people. The high availability page shows how redundancy turns this around, and the probability page explains why multiplying is correct.

How to read a formula

Mathematical notation is the shorthand mathematicians use: letters for numbers, and symbols for operations and relations. It looks intimidating, but it exists to make things shorter, not harder. A formula is a rule written in that notation: it says how to compute one quantity from others, such as "usable hosts = 232 − p − 2".

A few conventions cover most of what you will meet:

  • Letters are names for numbers. In (n - 1) \cdot s, the letter n is "the number of disks". Just like a variable in code, it stands for whatever value you fill in.
  • Writing things next to each other means multiplying. 2n is 2 × n, and ab is a × b. Formulas almost never use *; that is a programming habit.
  • A small raised symbol is a power. x^2 is x × x ("x squared").
  • A small lowered symbol is a label, not a calculation. x_1 ("x one" or "x sub one") and x_2 are just two different values, like x[1] and x[2] in a list.
  • Order matters as in Python. Brackets first, then powers, then multiplication and division, then addition and subtraction. The order of operations section shows this step by step.

Translating a formula step by step

To understand a formula, translate it into words, from the inside out. Take the hosts formula 2^{32 - p} - 2:

  1. Find the innermost part: 32 - p, "32 minus the prefix length". That is the number of host bits.
  2. The next layer: 2^{32 - p}, "2 to the power of the number of host bits". That is how many different addresses those bits can form.
  3. The outer layer: "minus 2", the two reserved addresses.
  4. Put it together: "two to the power of the host bits, minus two".

Once you can say a formula in words, you can also type it into Python, and you can check it with a small case you know the answer to: a /30 has 2 host bits, 2^2 - 2 = 2 usable hosts, which matches what network engineers know about point-to-point links.

Notation table

This table lists the symbols used across the Math for IT pages: how to write them, how to read them aloud, what they are in Python, and which page explains them. Other pages link here, so come back whenever a symbol is unfamiliar.

Notation Read aloud as In Python Explained on
a \cdot b, a \times b, ab a times b a * b Numbers
\frac{a}{b}, a/b a divided by b, a over b a / b Numbers
a^n a to the power n (a squared for n = 2) a ** n Powers
\sqrt{x}, \sqrt[n]{x} square root of x, n-th root of x math.sqrt(x), x ** (1 / n) Roots
\log_2 x, \log_{10} x, \ln x log base 2 of x, log base 10 of x, natural log of x math.log2(x), math.log10(x), math.log(x) Logarithms
x_1, x_2, x_i x one, x two, x sub i (labels) x[1], x[i] This page
=, \ne, \approx equals, is not equal to, is approximately equal to ==, !=, math.isclose(a, b) Equations
\lt, \le, \gt, \ge less than, at most (less than or equal to), greater than, at least <, <=, >, >= Inequalities
\pm plus or minus two calculations, one with + and one with − Equations
|x| absolute value of x abs(x) This page
\lfloor x \rfloor, \lceil x \rceil floor of x, ceiling of x math.floor(x), math.ceil(x) This page
a \bmod n a mod n (the remainder of a divided by n) a % n Modular arithmetic
a \equiv b \pmod{n} a is congruent to b modulo n a % n == b % n Modular arithmetic
a \mid b a divides b b % a == 0 Divisibility
\gcd(a, b), \operatorname{lcm}(a, b) greatest common divisor, least common multiple of a and b math.gcd(a, b), math.lcm(a, b) GCD and LCM
\sum_{i=1}^{n} x_i the sum of x sub i for i from 1 to n sum(x) This page
\prod_{i=1}^{n} x_i the product of x sub i for i from 1 to n math.prod(x) This page
n! n factorial: 1 × 2 × … × n math.factorial(n) Counting
\binom{n}{k} n choose k math.comb(n, k) Counting
\mathbb{N}, \mathbb{Z}, \mathbb{Q}, \mathbb{R} the natural numbers, integers, rational numbers, real numbers int, Fraction, float Number sets
x \in A, x \notin A x is an element of A, x is not an element of A x in A, x not in A Sets
A \cup B, A \cap B A union B, A intersection B A | B, A & B (sets) Sets
[a, b], [a, b) the interval from a to b, with b included or not included a <= x <= b, a <= x < b Inequalities
\lnot p, p \land q, p \lor q, p \oplus q not p, p and q, p or q, p xor q not p, p and q, p or q, p != q Logic
p \rightarrow q if p, then q (p implies q) (not p) or q Logic
f(x) f of x: the function f applied to x f(x) Functions
\Delta x delta x: the change in x x_new - x_old Rates of change
f'(x), \int_a^b f(x)\,dx f prime of x (the derivative), the integral of f from a to b approximated numerically Derivatives, Integrals
\mathbf{v}, \lVert \mathbf{v} \rVert the vector v, the length (norm) of v a list of numbers, math.hypot(*v) Vectors
\pi, e, \infty pi (3.14159…), e (2.71828…), infinity math.pi, math.e, math.inf Numbers
O(n) big O of n: grows at most proportionally to n (describes code, is not computed) Big O notation

Four of these symbols are used on almost every page, so they are explained here.

Floor and ceiling

Many IT answers must be whole numbers: you cannot buy 2.4 disks or run 3.7 servers. Two functions turn any number into a whole one, in a known direction:

  • The floor function \lfloor x \rfloor gives the largest whole number that is at most x: it rounds down. \lfloor 3.5 \rfloor = 3.
  • The ceiling function \lceil x \rceil gives the smallest whole number that is at least x: it rounds up. \lceil 3.5 \rceil = 4.

The brackets look like a floor (bars at the bottom) and a ceiling (bars at the top), which is an easy way to remember them. For negative numbers, "down" still means toward minus infinity: \lfloor -2.5 \rfloor = -3, not −2.

Worked example: Amara Okafor exports 1,234 tickets, 50 per page.

  1. Divide: 1,234 / 50 = 24.68.
  2. Full pages: \lfloor 24.68 \rfloor = 24.
  3. Pages needed, including the last partly filled one: \lceil 24.68 \rceil = 25.

Ask yourself which question you are answering: "how many fit completely?" needs the floor; "how many do I need?" needs the ceiling. In Python, a // b is the floor of a divided by b for whole numbers (see floor division).

Summation and product notation

Summation notation uses the capital Greek letter sigma, \Sigma, as shorthand for "add up a list of terms". The parts below and above the sigma say where a counter starts and stops, and the part after it says what to add for each value of the counter:

\sum_{i=1}^{10} i = 1 + 2 + 3 + \dots + 10 = 55

Read it as "the sum of i, for i from 1 to 10". It is a for loop in disguise:

total = 0
for i in range(1, 11):    # i from 1 to 10 (range stops before 11)
    total = total + i

A Kestrel example: if x_d is a customer's usage in kWh on day d, then a 30-day month's usage is \sum_{d=1}^{30} x_d, "the sum of x sub d for d from 1 to 30". The capital pi, \prod, works the same way but multiplies: the availability of a chain of services is the product of their availabilities, as in the example above.

Absolute value

The absolute value |x| is the distance of x from zero, without its sign: |-12| = 12 and |12| = 12. It is used when only the size of a difference matters, not its direction. If a smart meter reads 412 kWh and the estimate was 425 kWh, the error is |412 - 425| = |-13| = 13 kWh, whichever way round you subtract.

Notation choices on this site

Mathematical notation is not completely standardized: countries, textbooks and fields differ. These pages make the following choices and use them consistently.

"log" without a base

The logarithm is the classic trap. A logarithm always has a base, but the base is often left out, and what a bare "log" means depends on who wrote it:

  • On calculators and in engineering, log usually means base 10.
  • In mathematics, and in Python's math.log(x), it means base e, the natural logarithm.
  • In computer science, it often means base 2.

This site always writes the base: \log_2 n, \log_{10} x, or \ln x for the natural logarithm. The only exception is inside Big O notation, such as O(n \log n), where the base makes no difference to the growth rate. The logarithms page explains why.

Numbers, sets and intervals

  • Decimal point and thousands comma, as in English: 3.14 and 1,048,576. Dutch writes these the other way round (3,14 and 1.048.576).
  • The natural numbers \mathbb{N} include 0: \mathbb{N} = \{0, 1, 2, 3, \dots\}. Some books start at 1.
  • Intervals use the international notation with square and round brackets, such as [0, 1); see the inequalities page.
  • Units have a space after the number (100 Mbit/s, 8 TB, 3.5 kWh); percentages do not (99.9%).

Python as your calculator

Every calculation in this topic comes with a Python example that you can run, and almost every symbol in the notation table has a direct Python equivalent. Most of them are in the math module:

import math

print(math.floor(7 / 2))        # floor of 3.5
print(math.ceil(7 / 2))         # ceiling of 3.5
print(17 % 5)                   # 17 mod 5
print(abs(-12))                 # absolute value of -12
print(sum(range(1, 11)))        # sigma: i from 1 to 10
print(math.prod([2, 3, 4]))     # product of 2, 3 and 4
print(math.factorial(5))        # 5!
print(math.comb(5, 2))          # 5 choose 2
print(math.log2(1024))          # log base 2 of 1024
3
4
2
12
55
24
120
10
10.0

A second example converts the units in a transfer-time question. A 4 GB backup has to cross a 100 Mbit/s link. File sizes are in bytes, link speeds in bits per second, and one byte is 8 bits:

  1. Size in bits: 4 × 109 bytes × 8 = 32 × 109 bits.
  2. Divide by the rate: 32 × 109 / (100 × 106) = 320 seconds.
  3. Convert: 320 // 60 = 5 whole minutes, and 320 mod 60 = 20 seconds left over.
# Transfer time = size / rate (watch the bytes-to-bits factor of 8)
size_bytes = 4 * 10**9          # a 4 GB backup
rate_bits = 100 * 10**6         # 100 Mbit/s
seconds = size_bytes * 8 / rate_bits
print(f"{seconds:.0f} s = {seconds // 60:.0f} min {seconds % 60:.0f} s")
320 s = 5 min 20 s

How this topic is organized

The pages build from the ground up. If you are refreshing school math, start with the foundations; if you came for one IT question, jump to the group that answers it.