No number on the number line squares to −1, so we make one, i, and keep every rule of algebra. A complex number a + bi is then a point of the plane, its modulus is its distance from 0, and Python and NumPy calculate with it directly.
Explain why no real number squares to −1, and define the imaginary unit i by the rule that its square is −1.
Add, subtract and multiply complex numbers with the rules of algebra, replacing i squared by −1.
Plot a + bi as the point (a, b) of the complex plane, and name its real part and its imaginary part.
Compute the modulus of a complex number as its distance from 0, by hand and in Python.
In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
The question
Ask NumPy for the numbers whose square is \({-1}\), the zeros of \({x^2 + 1}\), and it does not refuse: it prints two numbers with the letter j in them. Yet the quadratic formula of lesson M01.3.3 says this equation has no real solution. So what are these numbers, how do you add and multiply them, and where do they live, if not on the number line? Machine learning meets them often: NumPy hands them back as the eigenvalues of a rotation (M03.1) and from every Fourier transform (M10.9).
Intuition
Every number on the number line has a square that is 0 or positive. A positive number times itself is positive, and a negative number times itself is positive too, because the two minus signs cancel. So no point of the line squares to \({-1}\).
The way out is the one taken long ago when negative numbers joined the counting numbers, and fractions joined the whole numbers: make a new number. Call it \(i\), the imaginary unit, and ask only one thing of it, that \({i^2 = -1}\). Then combine it with the old numbers, as in \({3 + 4i}\), \({-2 + i}\) or \(5i\). A number \({a + bi}\) like these is a complex number. It is built from two ordinary numbers, \(a\) and \(b\), and two numbers are exactly what it takes to name a point of the plane.
M01.9.1-F1
The complex number \({z = 3 + 4i}\) is the point \({(3, 4)}\). The number line is the horizontal axis, and the multiples of \(i\) run up the vertical axis.
So the number line is not thrown away. It becomes the horizontal axis of a plane, the real axis, and the multiples of \(i\) run up a vertical axis, the imaginary axis. The number \({a + bi}\) sits at the point \({(a, b)}\) of lesson M01.2.1: \(a\) across and \(b\) up. Why should \(i\) sit straight above 0, and not somewhere else? Lesson M01.9.2 answers that: multiplying by \(i\) turns the whole plane a quarter turn.
Build it up
Step 1. No real number squares to \({-1}\). Take any real number \(x\). If \({x > 0}\), then \(x^2\) is a positive number times a positive number, so it is positive. If \({x < 0}\), then \({-x}\) is positive, and \({x^2 = (-x) \times (-x)}\) is positive for the same reason. If \({x = 0}\), then \({x^2 = 0}\). So every real square is 0 or more, and \({x^2 = -1}\) has no real solution.
M01.9.1-F2
Squaring folds the number line onto its right half. Both \({-2}\) and \(2\) land on \(4\), and nothing lands left of 0.
Step 2. A new number. Make \(i\) with \({i^2 = -1}\), and keep every rule of algebra from M01.1.2: brackets, the order of operations, and the commutative, associative and distributive laws. Multiples of \(i\) follow at once. For example \({(2i)^2 = 2^2 \times i^2}\), which is \({4 \times (-1) = -4}\), so \({-4}\) has the two square roots \(2i\) and \({-2i}\). The name imaginary is historical: people once doubted that such numbers were real. They obey clear rules, and the lessons of this module put them to work.
Step 3. Two parts. A complex number \({z = a + bi}\) has a real part, written \({\operatorname{Re} z = a}\), and an imaginary part, written \({\operatorname{Im} z = b}\). The imaginary part is the real number \(b\), not \(bi\). A real number such as 5 is the complex number \({5 + 0i}\), and \(i\) itself is \({0 + 1i}\). In this module \(z\) is the number acted on, and a second number is \({u = c + di}\); the letter \(w\) is kept for weights.
Step 4. Adding and subtracting. Collect the parts, as with any brackets:
Subtracting works the same way: \({(3 + 4i) - (1 + i)}\) is \({2 + 3i}\). In the plane this is the adding of arrows from M01.2.4: the changes across add up, and so do the changes up.
Step 5. Multiplying. Multiply every part of one bracket by every part of the other, as in M01.1.2, and then replace \(i^2\) by \({-1}\). That one replacement is the only new rule. The worked example below does it in full.
The formal statement
NoteDefinition: complex numbers
The imaginary unit\(i\) is a number with \({i^2 = -1}\). A complex number is \({z = a + bi}\), where \(a\) and \(b\) are real numbers; its real part is \({\operatorname{Re} z = a}\) and its imaginary part is \({\operatorname{Im} z = b}\). Two complex numbers are equal when their real parts are equal and their imaginary parts are equal. The set of all complex numbers is written \(\mathbb{C}\).
The complex plane puts \({a + bi}\) at the point \({(a, b)}\). The modulus of \(z\) is its distance from 0:
\[
\abs{z} = \sqrt{a^2 + b^2} .
\]
The sum. For \({z = a + bi}\) and \({u = c + di}\), collecting the real parts and the imaginary parts gives
\[
z + u = (a + c) + (b + d)i .
\]
The product. Multiply out, every step shown:
\[
\begin{aligned}
zu &= (a + bi)(c + di) \\
&= ac + adi + bci + bd\,i^2 \\
&= ac + adi + bci - bd \\
&= (ac - bd) + (ad + bc)i .
\end{aligned}
\]
The second line multiplies each part of one bracket by each part of the other; the last of the four products is \({bi \times di = bd\,i^2}\). The third line uses \({i^2 = -1}\). The fourth gathers the real numbers and the multiples of \(i\).
The real numbers live inside. For two numbers whose imaginary parts are 0, the rules give back ordinary arithmetic: the sum of \({a + 0i}\) and \({c + 0i}\) is \({(a + c) + 0i}\), and their product is \({ac + 0i}\). So the real numbers sit inside \(\mathbb{C}\) as its real axis, and nothing about them changes. For them the modulus is the absolute value of M01.1.1, since \({\sqrt{a^2} = \abs{a}}\). That is why the two are written with the same bars: both measure distance from 0.
The order of a product does not matter. Swap \(z\) and \(u\) in the product formula and it gives \({(ca - db) + (cb + da)i}\), the same two numbers, so \({uz = zu}\). The other laws of algebra hold too, and each can be checked in the same way; Beck and others list them all as their Proposition 1.1.2.
Go deeper: complex numbers without any mystery
Beck and others start from pairs (their Definition 1.1.1). A complex number is a pair of real numbers \({(a, b)}\), added by the rule \({(a, b) + (c, d) = (a + c, b + d)}\) and multiplied by the rule
\[
\begin{aligned}
&(a, b) \cdot (c, d) \\
&\quad= (ac - bd,\ ad + bc) .
\end{aligned}
\]
Nothing is imaginary here: these are rules for pairs of ordinary numbers, and pairs \({(a, 0)}\) behave exactly like the real numbers \(a\). Now give the pair \({(0, 1)}\) the name \(i\). The rule gives
which is \({i^2 = -1}\), proved rather than assumed. And \({(b, 0) \cdot (0, 1) = (0, b)}\), so the pair \({(a, b)}\) is \({(a, 0) + (0, b)}\), which is \({a + bi}\). The code below uses exactly this view.
Worked example
Add, multiply and measure \({z = 3 + 4i}\) and \({u = 1 + i}\). These are the course’s running numbers: \(z\) is the arrow from \({P = (1, 2)}\) to \({Q = (4, 6)}\) of lesson M01.2.4, read as one number.
The sum. Real parts \({3 + 1}\), imaginary parts \({4 + 1}\):
\[
z + u = 4 + 5i .
\]
The product. There are four products, one for each pair of parts, and one of them contains \(i^2\).
M01.9.1-F3
The product as a table of four cells. The cell \({4i \times i}\) is \({4i^2 = -4}\), a real number, which is why the real part of the answer is \({3 - 4 = -1}\).
The formula agrees. With \({a = 3}\), \({b = 4}\), \({c = 1}\) and \({d = 1}\), the real part is \({ac - bd = 3 - 4 = -1}\) and the imaginary part is \({ad + bc = 3 + 4 = 7}\).
The modulus of \(z\) is 5, the distance from \(P\) to \(Q\) found in M01.2.3. And \({\sqrt{50}} = {\sqrt{25 \times 2}} = {5\sqrt{2}}\), about 7.0711, which is exactly \(\abs{z}\) times \(\abs{u}\). That is no accident: exercise 3 proves it, and the next lesson shows what it means.
Code
First from scratch, with a complex number stored as a pair (a, b): a tuple of its real part and its imaginary part (tuples come from P01.6). Each function unpacks the pairs into their parts and applies one formula of this lesson.
import mathdef add(z, u): a, b = z # unpack the two parts of z c, d = ureturn (a + c, b + d) # real parts together, imaginary parts togetherdef multiply(z, u): a, b = z c, d = ureturn (a * c - b * d, a * d + b * c) # the product formula, with i squared already -1def modulus(z): a, b = zreturn math.sqrt(a * a + b * b) # the distance from 0, by Pythagorasz, u = (3, 4), (1, 1)print("z + u =", add(z, u))print("z u =", multiply(z, u))print("|z| =", modulus(z), " |u| =", round(modulus(u), 4), " |zu| =", round(modulus(multiply(z, u)), 4))print("i times i =", multiply((0, 1), (0, 1)))
z + u = (4, 5)
z u = (-1, 7)
|z| = 5.0 |u| = 1.4142 |zu| = 7.0711
i times i = (-1, 0)
The last line is \({i^2 = -1}\), computed from the rule for pairs. Python also has complex numbers built in. It writes the imaginary unit as j, as electrical engineers do, who keep \(i\) for current: \({3 + 4i}\) is typed 3 + 4j, and \(i\) alone is 1j.
z =3+4j# the same number as complex(3, 4)u =complex(1, 1) # the real part first, then the imaginary partprint(z + u, z * u)print(z.real, z.imag) # the two parts, each a floatprint(abs(z), abs(u)) # abs gives the modulusprint(1j*1j) # i squared
Python prints (-1+0j) for \(i^2\): a complex number whose imaginary part is 0. Comparing two complex numbers with < is refused with a TypeError, and the pitfalls below show why no order could work. To ask which number lies nearer to 0, compare the moduli instead:
try: z < u # this line raises the errorexceptTypeError:print("z < u is refused: complex numbers have no order")print(abs(u) <abs(z)) # is u nearer to 0 than z is?
z < u is refused: complex numbers have no order
True
NumPy, previewed here and taught in P02, keeps many complex numbers in one array and works on all of them at once. np.abs gives every modulus in one call:
import numpy as npnumbers = np.array([3+4j, 1+1j, -1+7j])print(np.abs(numbers))
[5. 1.41421356 7.07106781]
Explore
The module’s interactive, the turn-and-scale explorer, lives in lesson M01.9.2. It opens on this lesson’s worked example: \({z = 3 + 4i}\) and \({u = 1 + i}\), with their sum \({4 + 5i}\) and their product \({-1 + 7i}\) printed under the drawing. Drag \(z\) around and watch both answers change; the next lesson explains what the product is doing to it.
Pitfalls
M01.9.1-F4
Wrong beside right. The modulus is the straight distance from 0, not the length of the walk along the axes.
“\({\abs{3 + 4i}}\) is \({3 + 4 = 7}\).”
Adding the parts measures the walk along the axes: 3 across, then 4 up. The modulus is the straight distance from 0, by Pythagoras: \({\sqrt{9 + 16} = 5}\). The two agree only when one of the parts is 0.
“The imaginary part of \({3 + 4i}\) is \(4i\).”
It is 4, a real number. Both parts of a complex number are real numbers; that is what lets \({3 + 4i}\) be plotted at the point \({(3, 4)}\), and it is what z.imag returns: 4.0, not 4j.
The rule \({\sqrt{a}\,\sqrt{b} = \sqrt{ab}}\) holds for numbers that are not negative, and breaks here. The square roots are \(2i\) and \(3i\), and \({2i \times 3i = 6i^2 = -6}\). Many books write \({i = \sqrt{-1}}\). That is a fine name, but calculate with \({i^2 = -1}\), and never by merging the square roots of negative numbers.
“Complex numbers can be sorted, so z < u should work.”
No order can keep the rule that a positive number times a positive number is positive. If \(i\) were positive, then \({i \times i}\) would be positive, but it is \({-1}\). If \(i\) were negative, then \({-i}\) would be positive, and \({(-i) \times (-i) = i^2 = -1}\) would have to be positive again. Either way a false statement follows, so Python refuses. To compare sizes, compare moduli.
Check yourself
Recall
1. Why is there no real number whose square is \({-1}\)?
Show answer
A positive number squared is positive, a negative number squared is positive (the two minus signs cancel), and 0 squared is 0. So every real square is 0 or more.
2. What are the real part and the imaginary part of \({-2 + 5i}\)?
Show answer
The real part is \({-2}\) and the imaginary part is 5, a real number.
3. Work out \({(2 + 3i) + (4 - i)}\) and \({(2 + 3i) - (4 - i)}\).
Show answer
\({6 + 2i}\) and \({-2 + 4i}\): the real parts and the imaginary parts are added, or subtracted, separately.
4. Where does the number \(i\) sit in the complex plane?
Show answer
At the point \({(0, 1)}\): one unit straight up from 0, on the imaginary axis.
5. What is the modulus of \({6 - 8i}\)?
Show answer
\({\sqrt{36 + 64} = \sqrt{100} = 10}\), its distance from 0.
Exercises
1.★ Work out \({(2 + i)(3 - 2i)}\). Then check that its modulus is \({\abs{2 + i}}\) times \({\abs{3 - 2i}}\).
Its modulus is \({\sqrt{64 + 1} = \sqrt{65}}\). The two moduli are \({\sqrt{4 + 1} = \sqrt{5}}\) and \({\sqrt{9 + 4} = \sqrt{13}}\), and \({\sqrt{5} \times \sqrt{13} = \sqrt{65}}\). They agree.
2.★★ Find \(i^3\), \(i^4\), \(i^5\) and \(i^{10}\). Where do the four powers \(i\), \(i^2\), \(i^3\) and \(i^4\) sit in the complex plane?
Show solution
\({i^3 = i^2 \times i = -i}\), and \({i^4} = {i^2 \times i^2} = {(-1) \times (-1)} = 1\). From there the powers repeat every four steps: \({i^5 = i^4 \times i = i}\), and \({i^{10} = i^8 \times i^2}\), which is \({1 \times (-1) = -1}\). The four powers \(i\), \({-1}\), \({-i}\) and \(1\) are the points \({(0, 1)}\), \({(-1, 0)}\), \({(0, -1)}\) and \({(1, 0)}\). They visit the four ends of the axes, each 1 from 0, a quarter of the way round each time. Lesson M01.9.2 shows that this is no coincidence.
3.★★★ Prove that \({\abs{zu} = \abs{z}\,\abs{u}}\) for any two complex numbers \({z = a + bi}\) and \({u = c + di}\).
Show solution
Both sides are 0 or more, so it is enough to show that their squares are equal. By the product formula, \({zu = (ac - bd) + (ad + bc)i}\), so
Taking square roots of both sides gives \({\abs{zu} = \abs{z}\,\abs{u}}\).
Summary card
A complex number \({a + bi}\) is the point \({(a, b)}\), and \({i^2 = -1}\).
M01.9.1-F1
The point \({(a, b)}\) is the number \({a + bi}\).
\({i^2 = -1}\). A complex number is \({z = a + bi}\), with \({\operatorname{Re} z = a}\) and \({\operatorname{Im} z = b}\).
Sum: \({(a + c) + (b + d)i}\). Product: \({(ac - bd) + (ad + bc)i}\).
Modulus: \({\abs{z} = \sqrt{a^2 + b^2}}\), the distance from 0, so \({\abs{3 + 4i} = 5}\).
Python: 3 + 4j, z.real, z.imag and abs(z); no < between complex numbers.
Sources and next steps
Sources. Each was opened and checked against this lesson on 12 November 2026.
Jay Abramson and others, Algebra and Trigonometry 2e, Section 2.4 Complex Numbers, OpenStax. Defines \(i\) as the square root of \({-1}\), so that \({i^2 = -1}\); the complex number \({a + bi}\) with real part \(a\) and imaginary part \(b\); the complex plane, with the real axis across and the imaginary axis up; adding by combining the real parts and the imaginary parts; multiplying like binomials with \({i^2 = -1}\); and the powers of \(i\), which repeat every four.
Matthias Beck, Gerald Marchesi, Dennis Pixton and Lucas Sabalka, A First Course in Complex Analysis, edition 1.6. Section 1.1: complex numbers as pairs of real numbers with the product rule (Definition 1.1.1), the laws of arithmetic (Proposition 1.1.2), \({(0, 1) \cdot (0, 1) = (-1, 0)}\) read as \({i^2 = -1}\) (equation 1.15), and the real and imaginary parts (Definition 1.1.3). Section 1.2: the real and imaginary axes, and the absolute value, or modulus, \({\sqrt{x^2 + y^2}}\) (Definition 1.2.2).
Python Software Foundation, Built-in types: numeric types, Python 3.12 documentation. The j suffix, complex(re, im), .real and .imag (each a float) and abs; and, in the section on comparisons, that <, <=, > and >= raise a TypeError when one of the arguments is a complex number.
Python issue tracker, issue 10562, Change ‘j’ for imaginary unit into an ‘i’, 2010 and 2011. Python’s core developers keep j: Python follows engineering, which writes \(j\), and in electrical engineering \(i\) stands for current.
NumPy reference, numpy.absolute, version 2.5: works element by element, gives \({\sqrt{a^2 + b^2}}\) for a complex input \({a + ib}\), and np.abs is a shorthand for it.