Skip to tool
ecech.
💻 Developer & Code

Column Letters Are Not Base 26, Because There Is No Zero

A is 1 and Z is 26, so the next is AA rather than A0. That missing zero digit is why the obvious conversion gives the wrong answer.

Converted

Where the boundaries are

Advertisement

How the calculation works

What comes after Z? X 24 Y 25 Z 26 AA 27 not A0 — there is no zero digit not BA — that is 53 In base 26 the digits run 0–25. Here they run 1–26, so every position is occupied. That is bijective base-26, and it is why ZZ is 702 while base 26 would say 675. Subtract one before each division when converting back, or multiples of 26 come out short.

How to Use This Tool

Paste letters, numbers, or a mix. The direction is detected automatically unless you force it.

The missing zero

Ordinary base 26 would have 26 digits meaning 0 to 25, so a two-digit number could start with the digit for zero. Column letters have no such digit: the alphabet supplies 1 to 26 and nothing else.

That makes the system bijective base-26, and it has a neat property — every positive integer has exactly one representation, with no leading-zero ambiguity. A is 1, Z is 26, AA is 27, ZZ is 702, and AAA is 703.

Compare with true base 26: ZZ would be 25×26 + 25 = 675, and the two systems disagree by 27. The gap grows with length, so a conversion that happens to work for single letters fails silently on two.

Getting the conversion right

Letters to a number is straightforward, because each letter is simply its position:

n = 0
for each character c:
    n = n * 26 + (position of c in the alphabet)   // A = 1

Number to letters is where implementations break. The correction is subtracting one before each step:

while n > 0:
    r = (n - 1) mod 26
    prepend letter r          // 0 = A
    n = floor((n - 1) / 26)

Leave out those two subtractions and any exact multiple of 26 produces an empty digit: 26 comes out as an empty string or "A@", and 52 becomes "AZ" shifted wrong. It is the single most common bug in spreadsheet tooling, and it only appears at Z, AZ, BZ and so on — which is exactly the input nobody tests.

Where the two systems part company A11 agree Z2625 already differ AA2726 ZZ702675 27 apart bijective base 26 Single letters agree by coincidence, which is why the bug survives testing.
The disagreement starts at Z and grows, so short test cases hide it.

Where the last column is

Modern spreadsheet formats stop at XFD, which is column 16,384 — exactly 214. The row limit is 1,048,576, or 220. Both are powers of two because they are storage limits, and XFD is simply what 16,384 spells.

Older formats stopped at IV, column 256, which is why a lot of legacy code assumes two letters is enough. Anything reading spreadsheets should handle three.

0-based and 1-based

Spreadsheets number columns from 1, so A is 1. Most programming libraries index arrays from 0, so A is 0. Both are shown here because converting between them is a separate, equally common off-by-one.

The safest habit when writing code is to convert letters directly to whichever base your library uses, rather than converting to the spreadsheet number and adjusting afterwards — the adjustment is easy to apply twice.

Advertisement

Frequently Asked Questions

What number is column AA in a spreadsheet?
27. A is 1 and Z is 26, so AA is the next one. It is not 26 or 0 — the system has no zero digit, which is exactly why the obvious base-26 conversion gives the wrong answer.
Are spreadsheet columns base 26?
No, they are bijective base-26. True base 26 has digits 0 to 25, allowing a leading zero. Column letters run 1 to 26 with no zero, so every integer has exactly one name — and ZZ is 702 where base 26 would say 675.
How do I convert a column number back to letters?
Subtract one before each step: take (n − 1) mod 26 as the letter, then set n to floor((n − 1) / 26) and repeat. Leaving out those subtractions breaks on every exact multiple of 26, starting at Z.
What is the last column in a spreadsheet?
XFD, which is column 16,384 — exactly 2^14. The row limit is 1,048,576, or 2^20. Older formats stopped at IV, column 256, which is why some legacy code assumes two letters is enough.
Why does my column conversion break at Z?
Because Z is the first exact multiple of 26, and that is where the missing subtraction shows up. Single letters work by coincidence and everything looks correct until a column name ends in Z.
Is column A number 0 or 1?
Both, depending on the context. Spreadsheets number from 1, so A is 1. Most programming libraries index from 0, so A is 0. Converting between the two is a separate off-by-one, and applying it twice is a common way to end up one column out.

Related tools in Developer & Code

Browse all Developer & Code tools
The desk where ecech. tools get written: a laptop, a notebook of to-dos and a whiteboard listing the tools on the site.

Made by one person

ecech. is not a content farm. Every tool here is written and checked by hand, one at a time, by someone who wanted the tool to exist and could not find a version that showed its working.

No accounts and no sign-in, and nothing you type reaches a server — every calculation on this page runs inside your browser. The ads are served by Google and do set their own cookies, which is set out in full on the privacy page. More about the site.