How to generate an invoice number
Use a simple sequence that never repeats and doesn't skip, such as INV-2026-001, INV-2026-002, and keep a log of every number you issue. Many tax systems expect invoice numbers to be unique and sequential, so avoid random IDs. Our free Invoice Maker has an Invoice # field you fill in; it doesn't count for you, so keep the log in a sheet or let your code hand out the next number.
Open the tool Invoice Maker — free online tool · Free
Formats that work
| Format | Example | Good for |
|---|---|---|
| Plain counter | 0001, 0002 | Very small businesses |
| Year and counter | INV-2026-014 | Most freelancers; resets cleanly each year |
| Client code and counter | ACME-007 | A few big clients who want their own series |
| Date and counter | 20261130-01 | Many invoices a day |
Rules to follow
- Unique: one number, one invoice, forever.
- In order: each new invoice gets the next number. Gaps raise questions in an audit.
- Don't reuse a cancelled number. Issue a credit note against it and a new invoice with the next number.
- Restart the counter each year only if the year is part of the number.
- Keep it short. The Invoice Maker field takes up to 30 characters.
- Rules differ between countries, so check with your accountant or tax office if you're unsure.
The next number in Excel or Google Sheets
If column A holds the numbers you've issued and A2 is the last one (INV-2026-014):
="INV-2026-"&TEXT(VALUE(RIGHT(A2,3))+1,"000")
Count this year's invoices instead (put it outside column A):
="INV-"&YEAR(TODAY())&"-"&TEXT(COUNTIF(A:A,"INV-"&YEAR(TODAY())&"-*")+1,"000")
The next number in code
Two people (or two server requests) must never get the same number. A counter table updated inside one transaction prevents that. Pass the result as invoice_number to our Invoice PDF API, where it's required (up to 40 characters) and printed in the header.
import sqlite3, datetime
db = sqlite3.connect("billing.db", isolation_level=None)
db.execute("CREATE TABLE IF NOT EXISTS counters (year INTEGER PRIMARY KEY, last INTEGER NOT NULL)")
def next_invoice_number() -> str:
year = datetime.date.today().year
db.execute("BEGIN IMMEDIATE") # locks the table until COMMIT
db.execute("INSERT INTO counters (year, last) VALUES (?, 0) ON CONFLICT(year) DO NOTHING", (year,))
db.execute("UPDATE counters SET last = last + 1 WHERE year = ?", (year,))
n = db.execute("SELECT last FROM counters WHERE year = ?", (year,)).fetchone()[0]
db.execute("COMMIT")
return f"INV-{year}-{n:04d}"
Using it in the Invoice Maker
- Open /tools/invoice-maker. The Invoice # field starts at INV-001.
- Type your next number from your log.
- Fill in the client and items, then Save as PDF.
- Write the number, client, amount and date in your log straight away.
The product
Questions
Can I start at a number other than 1?
Yes. Starting at 1001 or 0100 is common and fine, as long as you count up from there without gaps.
What if I made a mistake on an invoice I already sent?
Leave its number in your records, issue a credit note that cancels it, and send a corrected invoice with the next number.
Does the Invoice Maker remember my last number?
No. Nothing is saved between visits, so the number comes from your own log.
Related
Updated 2026-12-01