Format-Preserving Encryption (FPE)

What is format-preserving encryption (FPE)?

Format-preserving encryption (FPE) is a type of encryption whose output keeps the same format and length as the input. A 16-digit card number encrypts to another 16-digit number, and a nine-digit Social Security number stays nine digits. Anyone with the key can decrypt the value, so the key must be tightly protected.

For example, a bank wants to give its analytics team a copy of a customer table. The card number column in the old database only accepts 16 digits. Standard encryption would produce a long string of mixed characters that breaks the schema and the reports built on it. FPE produces a different 16-digit number that fits the column, so the copy works without code changes.

How format-preserving encryption works

FPE uses a standard cipher, usually AES, in a special mode that maps each input to an output from the same set of allowed characters. NIST Special Publication 800-38G describes approved FPE methods, including the FF1 mode. Each encryption uses a secret key and can also use a “tweak,” an extra input that makes the same value encrypt differently in different contexts.

  • The output has the same length and character set as the input.
  • With the same key and tweak, the same input always gives the same output, so joins still work.
  • Very short inputs give weak protection, so standards set a minimum input size.

Format-preserving encryption vs tokenization

Format-preserving encryption Tokenization
How the value is protected Math with a secret key Replaced with a token; the real value is kept in a vault
Who can reverse it Anyone with the key Callers the vault authorizes
If the key or vault is exposed Every value encrypted with that key is exposed Values in the vault are exposed; tokens alone reveal nothing
What you run Key management A token vault and its access policy

Both keep data usable in existing systems. The choice usually comes down to key management, scale and how access to real values should be controlled. This post compares format-preserving encryption and tokenization in more depth.

Why format-preserving encryption matters for AI systems

FPE solves a schema problem, but it can create a reading problem for AI. An encrypted card number still looks like a card number, and an encrypted name may look like random letters. A model cannot tell that the value is protected or what kind of value it is. Typed tokens carry a label, so the model knows it is looking at a person or an email and can reason around it. FPE output also stays personal data under laws like the GDPR, because the key can reverse it.

How Protecto helps

Protecto Vault uses tokenization with context-preserving, format-preserving masking. Tokens can keep the shape of the original value and still carry an entity tag, for example <PHONE>8349201756</PHONE>, so schemas keep working and AI models know what each value is. Authorized users and tools receive real values only where policy allows.

Frequently asked questions

Is format-preserving encryption secure?

It can be when it uses an approved mode such as FF1 from NIST SP 800-38G, a strong key and inputs above the minimum size. Its security depends heavily on protecting the key.

Is format-preserving encryption the same as tokenization?

No. FPE computes the output from the value and a key, so anyone with the key can reverse it. Tokenization replaces the value with a token and keeps the original in a vault that controls access.

Which standard defines format-preserving encryption?

NIST Special Publication 800-38G describes approved methods for format-preserving encryption, including the FF1 mode built on AES.

Related terms

Data encryption · Tokenization · PCI data · Context-preserving masking

Book a demo

See Protecto on your own data

Book a demo to see how Protecto finds and masks sensitive data before it reaches any AI model.

New: Protecto now runs inside LiteLLM. Control what sensitive data your models and tools see.
Read the launch blog