← Fun & Random

Luhn Algorithm Validator

Validate and generate Luhn-valid test numbers directly in your browser.

Validate

Generate Test Numbers

Card network

These are algorithmically valid test numbers only. They are not real card numbers.

Use this tool from AI agents

This tool's engine is available to AI agents over MCP as luhn_validate. Add the Clean.tools server, then your agent can call it directly.

Claude Code
claude mcp add --transport http clean-tools https://mcp.clean.tools/mcp
Claude Desktop (mcpServers)
{"mcpServers":{"clean-tools":{"command":"npx","args":["-y","@clean-tools/mcp"]}}}
Cursor
https://mcp.clean.tools/mcp

Or call it over plain HTTP from any script. Same engine, JSON in and JSON out, no key:

curl
curl -s https://api.clean.tools/v1/luhn_validate \ -H 'content-type: application/json' \ -d '{"number":"4539 1488 0343 6467"}'
JavaScript
const res = await fetch('https://api.clean.tools/v1/luhn_validate', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ number: '4539 1488 0343 6467' }) }); const data = await res.json();

How it works

The Luhn algorithm (also called the mod-10 algorithm) is a checksum formula used to validate identification numbers such as credit card numbers. Starting from the rightmost digit, every second digit is doubled. If the doubled value exceeds 9, subtract 9. Sum all the digits. If the total modulo 10 equals zero, the number is valid.

This tool validates numbers against the Luhn algorithm in real time and generates test numbers with correct prefixes and check digits for common card networks. Everything runs locally in your browser. No data is sent to a server. If you would rather check numbers from a script or an AI agent, the same engine is available through the Clean.tools Luhn API as luhn_validate and as an MCP server, or install the @clean-tools/mcp package from npm.

Frequently asked questions

Does passing the Luhn check mean a card number is real?

No. The Luhn check only confirms that the final check digit is mathematically consistent with the rest of the number. It cannot tell you whether an account was ever issued, is active, or has funds.

Why does it accept numbers that are not 15 or 16 digits?

The Luhn algorithm operates on any string of digits, so the validator reports the checksum result regardless of length. It does not enforce card-network length rules, which makes it useful for IMEIs, national IDs, and other Luhn-based numbers as well.

Does the input handle spaces and dashes?

Yes. Spaces and hyphens are stripped before validation, so 4539 1488 0343 6467 validates the same as the unspaced form. Any other non-digit character shows an "Enter digits only" message instead.

Are the generated numbers safe to use in tests?

Yes. They carry real network prefixes and a valid check digit but the middle digits are randomly generated with the Web Crypto API, so they pass format validation without matching any issued account.

Can I use this from the command line or an AI agent?

Yes. The same validator is exposed as a REST endpoint at https://api.clean.tools/v1/luhn_validate, so you can POST a number and read the result back as JSON from any script. It also runs as an MCP server you can add to Claude, Claude Code, or Cursor, and the @clean-tools/mcp npm package launches it as a local stdio server for offline use.


More tools from Clean.tools

View all tools

Use Clean.tools from your AI agent

This tool is also luhn_validate on the Clean.tools MCP server — the same engine, callable by your AI agent directly. No key, no signup: requests are processed in memory and request contents are never stored.

Claude Code
claude mcp add --scope user --transport http clean-tools https://mcp.clean.tools/mcp
Any MCP client (streamable HTTP, authless)
https://mcp.clean.tools/mcp

Every tool, the REST API, and setup for Cursor, Claude Desktop, VS Code & more →