Why Excel columns are not ordinary base-26
Spreadsheet column labels look like base-26, but they use a quirk called bijective numeration. In ordinary base-26 you would need a zero symbol, but column labels have no zero. The symbols run A through Z (values 1 through 26), so after Z comes AA — not BA. That single difference breaks naive base-26 conversion for multi-letter columns.
This matters in practice any time you programmatically generate column references — in Python pandas, in database export scripts, in formula engines, or in data pipelines that address columns by index.
The algorithms
Letters to number — scan left to right, accumulating position:
total = 0
for each letter (left to right):
total = total × 26 + letterValue (A=1 … Z=26)
So AB is 1 × 26 + 2 = 28. ZZ is 26 × 26 + 26 = 702. AAA is 1 × 676 + 1 × 26 + 1 = 703.
Number to letters — peel off letters from the right, subtracting one each step to account for the missing zero:
while n > 0:
n = n − 1
letter = 'A' + (n mod 26)
prepend letter
n = floor(n / 26)
The subtract-one before each division is the key. Without it, column 26 would map to Z0 (impossible), not Z. With it, 26 maps correctly to Z, 27 to AA, and so on.
Reference: key column values
| Label | Index | Notes |
|---|---|---|
| A | 1 | First column |
| Z | 26 | Last single-letter column |
| AA | 27 | First two-letter column |
| AZ | 52 | |
| BA | 53 | |
| ZZ | 702 | Last two-letter column |
| AAA | 703 | First three-letter column |
| XFD | 16384 | Last column in modern Excel (1,048,576 rows) |
| XFE | 16385 | Beyond Excel’s range; valid in the math, not in a sheet |
Common use cases
- Generating CSV headers from a column count: convert integers 1 through N to labels A, B, …, Z, AA, AB, … to match what Excel would call those columns.
- Reading VLOOKUP or INDEX formulas from code: when you know the column number from your data model and need the letter label for a formula string.
- Validating data exports: check that an exported column reference matches the expected index before processing.
- Formula engines and low-code tools: many formula parsing libraries expose columns by index internally and display them by letter in the UI.
The converter handles arbitrarily long labels and any positive integer index, so it is safe for large datasets that exceed the XFD limit if you are working outside Excel itself.