UK Sort Code Validation in Node.js — British Banking
Sort codes are 6-digit numbers that identify UK bank branches for domestic payments. Here's how they work, what each digit group means, and how to validate them in production using a single API call.
In this guide
1. What is a sort code?
A sort code is a 6-digit number used in the United Kingdom and Ireland to identify a specific bank branch. Sort codes are the UK equivalent of ABA routing numbers in the US or BSB codes in Australia — they tell the payment system which bank and branch an account belongs to.
Sort codes are required for virtually every type of UK domestic payment:
- BACS payments — Direct Debits, Direct Credits, standing orders (batch processing, 3-day cycle)
- Faster Payments — near-instant transfers up to £1,000,000 (most banks support this)
- CHAPS — same-day high-value payments, typically used for property purchases
- Cheque clearing — paper cheques processed through the Image Clearing System
If your application accepts UK bank account details — for payouts, Direct Debits, or account verification — you need to validate the sort code before initiating any transaction.
2. Sort code anatomy — the XX-XX-XX format
A sort code consists of three pairs of digits, conventionally written with hyphens:
Bank code (first 2 digits)
The first two digits identify the bank or financial institution. For example, 20 is Barclays, 30 is Lloyds, 40 is HSBC, and 60 is NatWest. Some banks use multiple bank code prefixes due to mergers and acquisitions.
Area code (middle 2 digits)
The middle two digits traditionally identified the processing centre or clearing area. While this geographic significance has diminished with centralised processing, the area code still helps narrow down the specific part of the bank's network.
Branch code (last 2 digits)
The final two digits identify the specific branch within the bank's area. Combined with the bank and area codes, these six digits uniquely identify a branch (or virtual branch for online-only accounts) in the UK payment system.
| Bank Code | Bank |
|---|---|
| 20 | Barclays |
| 23 | Bank of Scotland |
| 30 | Lloyds Bank |
| 40 | HSBC |
| 50 | Allied Irish Banks (GB) |
| 55 | TSB Bank |
| 60 | NatWest |
| 77 | Clydesdale Bank |
| 80 | Bank of Scotland |
| 83 | Royal Bank of Scotland |
3. How sort codes work — bank identification
Unlike ABA routing numbers or IBANs, UK sort codes do not include a check digit. Validation relies on matching the sort code against the official directory maintained by the Bankers' Automated Clearing Services (BACS).
The EISCD directory
The Extended Industry Sort Code Directory (EISCD) is the official database of all active sort codes in the UK. Published by BACS, it maps each sort code to the owning bank, branch name, address, and the clearing systems the branch participates in (BACS, Faster Payments, CHAPS). A sort code that is not in the EISCD is either inactive, invalid, or belongs to a private clearing arrangement.
Modulus checking
While sort codes themselves have no check digit, the combination of a sort code and account number is validated using a modulus check (defined in the VocaLink "Standard 18" specification). This check uses sort-code-specific weights and modulus values to verify that a given account number is valid for that particular sort code. The IsValid API performs format validation and structural checks on the sort code itself.
Sort codes and IBANs
UK IBANs embed the sort code and account number. A UK IBAN follows the format GBxx BBBB SSSSSS AAAAAAAA where SSSSSS is the 6-digit sort code and AAAAAAAA is the 8-digit account number. When processing international payments to the UK, you may need to extract and validate the sort code from within the IBAN.
4. Why sort code validation matters
UK payment processing
Every BACS payment, Faster Payment, and CHAPS transfer requires a valid sort code. An invalid sort code will cause the payment to fail at the clearing stage, resulting in returned funds, failed Direct Debits, and poor customer experience. Validating the sort code before initiating a payment catches errors at the point of entry.
BACS Direct Debit mandates
When setting up a Direct Debit mandate, the sort code and account number must be validated against the EISCD. BACS will reject mandates with invalid sort codes, and repeated failed mandates can result in penalties and compliance issues under the Direct Debit Guarantee scheme.
Faster Payments availability
Not all sort codes participate in the Faster Payments scheme. Some building society sort codes only support BACS (3-day cycle) and not real-time payments. Validating the sort code helps determine which payment rails are available for a given account.
Open Banking and PSD2
Under Open Banking (PSD2), account information service providers (AISPs) and payment initiation service providers (PISPs) need to validate sort codes as part of payment initiation and account verification workflows. Sort code validation is a fundamental building block for Confirmation of Payee (CoP) checks.
5. The right solution
The IsValid Sort Code API validates the sort code format and returns the normalised and formatted representations in a single GET request. The response includes the raw 6-digit sort code and the hyphenated XX-XX-XX format.
Get your free API key at isvalid.dev. The free tier includes 100 calls per day — enough for most development and low-volume production use.
Full parameter reference and response schema: Sort Code Validation API docs →
6. Node.js code example
Using the IsValid SDK or the native fetch API.
import { createClient } from '@isvalid-dev/sdk'; const iv = createClient({ apiKey: process.env.ISVALID_API_KEY }); // ── Validate a sort code ──────────────────────────────────────────────────── const result = await iv.gb.sortCode('20-00-00'); if (!result.valid) { console.log('Invalid sort code'); } else { console.log(`Valid sort code: ${result.formatted}`); // "20-00-00" console.log(`Raw: ${result.sortCode}`); // "200000" }
In a UK bank account verification flow, you might use it like this:
// routes/bank-account.js (Express) app.post('/bank-account/gb', async (req, res) => { const { sortCode, accountNumber, ...rest } = req.body; let sortCodeCheck; try { sortCodeCheck = await validateSortCode(sortCode); } catch { return res.status(502).json({ error: 'Sort code validation service unavailable' }); } if (!sortCodeCheck.valid) { return res.status(400).json({ error: 'Invalid sort code' }); } // Normalise the sort code for storage const normalised = sortCodeCheck.sortCode; // "200000" const display = sortCodeCheck.formatted; // "20-00-00" console.log(`Verified sort code: ${display}`); await linkBankAccount({ sortCode: normalised, accountNumber, ...rest, }); res.json({ success: true, sortCode: display }); });
7. cURL example
Validate a sort code from the command line:
curl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.isvalid.dev/v0/gb/sort-code?value=20-00-00"
You can also pass the sort code without hyphens:
curl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.isvalid.dev/v0/gb/sort-code?value=200000"
Test with an invalid sort code:
curl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.isvalid.dev/v0/gb/sort-code?value=99-99-99"
8. Understanding the response
Valid sort code:
{ "valid": true, "sortCode": "200000", "formatted": "20-00-00" }
Invalid sort code:
{ "valid": false }
| Field | Type | Description |
|---|---|---|
| valid | boolean | Whether the sort code passes format validation |
| sortCode | string | The normalised 6-digit sort code without hyphens (e.g. "200000") |
| formatted | string | The sort code in standard XX-XX-XX format (e.g. "20-00-00") |
9. Edge cases to handle
Building society sort codes
Building societies (e.g. Nationwide, Yorkshire Building Society) use sort codes like any high-street bank, but their account number structure can differ. Some building societies require a "roll number" in addition to the account number for identification. When accepting building society details, always provide a field for the roll number alongside the sort code and account number.
// Handle building society accounts function getBankDetailsForm(sortCode) { const result = validateSortCode(sortCode); // Building societies may need additional reference return { sortCode: result.formatted, requiresRollNumber: isBuildingSociety(sortCode), }; }
Merged banks and redirected sort codes
When banks merge, sort codes from the acquired bank may be redirected to the acquiring bank's systems. For example, when TSB separated from Lloyds, many sort codes were reassigned. Similarly, Clydesdale Bank and Yorkshire Bank sort codes were affected by the Virgin Money acquisition. A sort code that was valid last year may now route differently or have been deactivated entirely.
Digital-only bank sort codes
Neobanks like Monzo, Starling, and Revolut use sort codes assigned to their banking license partner or their own allocation. Monzo uses sort codes starting with 04 (via their e-money license) and Starling uses sort codes starting with 60 (via NatWest's agency arrangement). These sort codes are fully valid and participate in Faster Payments.
Format normalisation
Users may enter sort codes in various formats: 20-00-00, 200000, 20 00 00, or even 20.00.00. Always normalise the input by stripping non-digit characters before validation. The IsValid API accepts sort codes in any common format and returns both the raw and formatted versions.
Summary
See also
Validate UK sort codes instantly
Free tier includes 100 API calls per day. No credit card required. Format validation, normalisation, and formatted output in a single call.