Math & trig function

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)
ArgumentWhat it means
x_numRequiredThe x coordinate (east/horizontal). Note: x comes first in Excel.
y_numRequiredThe 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

D2fx=DEGREES(ATAN2(B2, C2))
ABCD
1DropEast (km)North (km)
2Customer 173-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

D2fx=DEGREES(ATAN2(B2, C2))
ABCD
1Pointxy
2Sensor B-22135

Result: 135

The point is up and to the left, at 135°. =DEGREES(ATAN(C2/B2)) would return −45°, pointing the opposite way.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 13 KB

Common errors and how to fix them

ErrorWhy it happensFix
#DIV/0!Both x_num and y_num are 0.The origin has no direction; test for it with IF.
Rotated resultArguments 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.

LanguageFunction name
CzechARCTG2
DanishARCTAN2
DutchBOOGTAN2
GermanARCTAN2
HungarianARCTAN2
ItalianARCTAN.2
Norwegian (Bokmål)ARCTAN2
SwedishARCTAN2