ATAN2 function
Returns the angle from the x-axis to a point (x, y) in radians, from −π to π, using both coordinates.
Available in All versions of Excel, Excel for the web, Excel for Mac
In every Excel versionWorks in Google Sheets
Syntax
ATAN2(x_num, y_num)| Argument | What it means | |
|---|---|---|
x_num | Required | The x coordinate (east/horizontal). Note: x comes first in Excel. |
y_num | Required | The y coordinate (north/vertical). |
Returns: An angle in radians greater than −π and up to π.
How ATAN2 works
ATAN2 gives the direction of a point from the origin, taking the signs of both coordinates into account, so it can return any angle around the full circle. Use it for the direction of travel from an x/y offset, the angle of a wind vector from its components, or converting coordinates to polar form. Where ATAN(y/x) cannot distinguish opposite directions and fails when x = 0, ATAN2 handles every case.
Watch the argument order: Excel uses ATAN2(x, y), the reverse of most programming languages (atan2(y, x) in Python, JavaScript or C). Mixing them up rotates the result. The answer is in radians between −π and π, measured counter-clockwise from the positive x-axis; convert with DEGREES, and add 360 with MOD for a 0–360° range. Both arguments 0 returns #DIV/0!.
Examples
1Direction of a delivery from the depot
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Drop | East (km) | North (km) | |
| 2 | Customer 17 | 3 | -4 | -53.13 |
Result: -53.13
The customer is 3 km east and 4 km south, at −53.13° from due east (2 decimals). =MOD(DEGREES(ATAN2(B2,C2)),360) gives 306.87°.
2Why ATAN is not enough
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Point | x | y | |
| 2 | Sensor B | -2 | 2 | 135 |
Result: 135
The point is up and to the left, at 135°. =DEGREES(ATAN(C2/B2)) would return −45°, pointing the opposite way.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#DIV/0! | Both x_num and y_num are 0. | The origin has no direction; test for it with IF. |
Rotated result | Arguments swapped as in other languages (y first). | In Excel, x comes first. |
Tips
- Compass bearing (0° = north, clockwise):
=MOD(DEGREES(ATAN2(north, east)), 360)— swapping the inputs on purpose turns the maths angle into a bearing. - Polar radius to go with the angle:
=SQRT(x^2+y^2).
Google Sheets
ATAN2 also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
ATAN2 in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Czech | ARCTG2 |
| Danish | ARCTAN2 |
| Dutch | BOOGTAN2 |
| German | ARCTAN2 |
| Hungarian | ARCTAN2 |
| Italian | ARCTAN.2 |
| Norwegian (Bokmål) | ARCTAN2 |
| Swedish | ARCTAN2 |