Keycloak Ops
Isometric board of glowing linked cubes with a user badge on a pedestal and an outside block joining by arrow, mapping realms, clients and tokens
fundamentals

What Is a Keycloak Realm? Realm vs Client and How to Create

A Keycloak realm is an isolated tenant with its own users, roles, clients and signing keys. Learn when to use one or several realms and how to create one.

By Keycloak Ops Editorial · ·Updated · 13 min read

A Keycloak realm is an isolated tenant inside one Keycloak server. It holds its own users, credentials, roles, groups, clients, login flows and signing keys, and it issues tokens from its own URL path, /realms/{realm-name}. A realm authenticates only the users it controls. Every installation starts with a master realm reserved for administration.

Keycloak is an open source identity and access management server, and the realm is its administrative namespace. A client represents one application inside that namespace, so one realm usually holds many clients. Start with the realm boundary, then decide which applications belong inside it and what each application should receive in its tokens.

Evidence note: this page is based on Keycloak’s official documentation (console steps checked against the Keycloak 26.8 docs on 2026-11-18). Nothing here was run on a test server, and the design examples are planning scenarios, not measured results.

For related deployment and troubleshooting topics, browse our single-sign-on operations guides.

What Is a Realm in Keycloak?

A realm is the unit Keycloak uses to separate identities. The Server Administration Guide says a realm “manages a set of users, credentials, roles, and groups,” that a user belongs to and logs into a realm, and that realms “are isolated from one another.” Keycloak’s Docker getting-started guide calls a realm “equivalent to a tenant.”

The realm name is also part of every protocol URL. Keycloak’s OIDC endpoint reference lists each endpoint as a path under /realms/{realm-name}, prefixed with the server’s base URL. The realm root is the issuer: the cross-domain chaining guide gives http://localhost:8080/realms/domainb as the issuer for realm domainb.

Endpoint Path under the server base URL
Issuer /realms/{realm-name}
Discovery document /realms/{realm-name}/.well-known/openid-configuration
Token /realms/{realm-name}/protocol/openid-connect/token
Signing keys (JWKS) /realms/{realm-name}/protocol/openid-connect/certs
Account Console /realms/{realm-name}/account

Realms Are Isolation Boundaries

A realm manages and authenticates its own users. Creating an account in one realm does not automatically create an account in another or establish shared login between them. Identity brokering can deliberately connect identity providers, but that is an integration you configure.

Applications must use the issuer for the intended realm. Two clients with the same client ID in different realms are separate registrations. Treat the realm name and issuer as part of an application’s configuration contract.

Keycloak Realm vs Client: What Is the Difference?

A realm is the security domain: it owns users, login policy, sessions and signing keys. A client is one application registered inside a realm, with its own client ID, redirect URIs, public or confidential type and client roles. One realm usually holds many clients, and a client never spans realms.

Realm Client
Represents A user population and its login rules One application or service
Typical count One per independently managed population Many per realm
Configured there Users, groups, realm roles, flows, keys, sessions Redirect URIs, credentials, client roles, dedicated scope
Identified by The realm name in the issuer and endpoint URLs Its client ID in authorization and token requests

One Realm vs Many: Choose the User Boundary First

One realm is a useful starting point when the same people use several applications under a shared account and login policy. For example, a portal, a document service, and a dashboard can be three clients in one realm. Client roles can describe different permissions in those applications without splitting the user directory.

Several realms make sense when populations need independently managed identities and realm policies. Keycloak’s administration guide uses employees and customers as an example of separate populations. The decision is about who owns the accounts, which login rules apply, and which applications those accounts should reach.

Design question One realm is a starting point when… Consider separate realms when…
Accounts Applications share the same account population Populations must be managed independently
Login policy Realm settings can serve the applications together Populations need separate realm settings
Application access Client roles express the differences Separate identity namespaces are required
Administration The same desk manages the population Administration should be delegated by realm

Write down the reason for each boundary before creating it. A realm per application multiplies the user, role, and client configuration that operators must maintain. Conversely, forcing unrelated populations into one realm makes the application authorization model carry more of the separation.

Realm isolation also differs from infrastructure isolation. Realms on the same deployment share its process, database service, and operational lifecycle. If a requirement concerns independent outages or infrastructure administration, evaluate separate deployments as well as separate realms. Adding a realm alone does not create dedicated compute or a separate database server.

Organizations: Many Tenants in One Realm

For B2B products serving many customer companies, consider Organizations before creating a realm per customer. The Keycloak 26.0.0 release of October 2024 made the feature fully supported, and the organizations documentation describes it as multi-tenancy within a realm. The documentation says organization-specific claims are passed to applications through tokens. Separate realms still fit customers that need different realm-level policy or delegated administration.

The Master Realm: Keep Applications in Their Own Realm

Keycloak creates the master realm for administration. The Server Administration Guide says to “use the master realm only to create and manage the realms in your system.” Create an application realm before registering application clients or onboarding their users.

The reason is privilege separation: a master administrator with the global admin role can manage every realm, and application roles should not mix with that model. For what else lives inside a realm, including keys, flows and the master realm’s contents, see what is a realm in Keycloak.

How to Create a Keycloak Realm

Sign in to the Admin Console as a master administrator, or script the job with the Admin CLI. The console steps follow Keycloak’s getting-started guide, checked against the Keycloak 26.8 docs on 2026-11-18:

  1. Open the Admin Console at http://localhost:8080/admin.
  2. Click Manage realms in the left column, then click Create realm.
  3. Enter myrealm in the Realm name field. It becomes part of every endpoint URL, so settle it before sharing issuer URLs.
  4. Click Create.
  5. Under Users, click Create new user, fill in Username, then click Create.
  6. Click Credentials, enter a password under Set password, and set Temporary to Off.
  7. Sign in as that user at http://localhost:8080/realms/myrealm/account to confirm the realm works.

From a shell, use the Admin CLI. The Admin CLI documentation says Keycloak “packages the Admin CLI server distribution with the execution scripts in the bin directory.” The containers guide runs kc.sh from /opt/keycloak/bin in the official image; it does not name kcadm.sh, so look for it there as this site’s inference, not a documented path. The example logs in against master, then creates and lists realms. The docs note that Keycloak disables realms by default, hence enabled=true:

kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin
kcadm.sh create realms -s realm=demorealm -s enabled=true
kcadm.sh get realms

Register Your First Client

A new realm has no application registered yet. These steps follow the getting-started guide, which uses its own test app as the redirect target:

  1. In the Admin Console, select myrealm next to Current realm.
  2. Click Clients, then Create client.
  3. Set Client type to OpenID Connect and Client ID to myclient.
  4. Click Next.
  5. Confirm Standard flow is enabled, then click Next.
  6. Under Login settings, set Valid redirect URIs to your application’s callback (the guide uses https://www.keycloak.org/app/*) and Web origins to its origin (the guide uses https://www.keycloak.org).
  7. Click Save.

The Admin CLI documentation shows the scripted equivalent:

kcadm.sh create clients -r demorealm -s clientId=myapp -s enabled=true

Use your real application URLs for redirect URIs in any environment beyond a lab.

Realm Roles vs Client Roles

Realm roles apply across the whole realm. Client roles are scoped to one application; the Server Administration Guide calls them “a role namespace dedicated to the client.” In this site’s view, use a realm role for a meaning shared by every application, such as staff, and a client role for a permission one application checks, such as an inventory editor.

Clients, Scopes and Roles

A client represents an application requesting tokens. Confidential clients can hold a secret and are used by server side applications. Public clients cannot keep a secret, which covers browser and mobile applications, and must rely on the authorization code flow with PKCE rather than any flow that returns tokens directly.

Assign roles to groups rather than individual users so membership changes do not require touching authorization data. Composite roles bundle other roles and are useful, but deep nesting makes effective permissions hard to reason about.

Keep role assignment distinct from token contents. Giving a user a role and choosing whether a client receives that role in a token are separate decisions. Review both when an application reports missing permissions.

Client Scopes and Audience Mapping

A client scope groups protocol mappers and role scope mappings that can be shared by clients. Protocol mappers determine claims in tokens or assertions; role scope mappings constrain which assigned roles are available to the client. Sharing a scope is useful when several applications need the same claim definition.

Default client scopes apply when tokens are issued, regardless of the OIDC request’s scope parameter. Optional client scopes apply when the client requests them through that parameter. The dedicated client scope holds mappings specific to one client. Put shared mappings in a reusable scope and keep application-specific mappings with the application.

Audience mapping answers a different question: which service should accept the access token? The aud claim identifies intended recipients. A token being signed by the right realm is insufficient grounds for every API in that realm to accept it.

Keycloak documents an Audience Resolve mapper that derives audiences from applicable client roles, and a Hardcoded Audience mapper for explicitly adding a configured audience. Choose the mapping that matches the API contract, and configure the API to validate its expected audience as well as the issuer, signature, and expiry.

For a hypothetical portal calling an inventory API, write down the expected API audience before choosing the mapper. Check a token issued to the portal for that audience and for the inventory permissions it needs. Avoid adding every API as an audience just to remove an integration error.

The client’s Client scopes → Evaluate view can show effective mappings and example tokens for a selected user and requested scopes. Compare default-only output with output that includes an optional scope. Check access tokens, ID tokens, and UserInfo separately: their consumers and purposes differ. Keep claims limited to what those consumers need, and avoid assuming token byte size equals cached session size.

Authentication Flows and Federation

Authentication flows are configurable chains of executions covering login, registration, password reset, and step up authentication. Copy a built in flow before editing it, and keep custom flows minimal, since a misconfigured required execution can lock everyone out of a realm.

User federation connects Keycloak to an existing LDAP or Active Directory source. Decide early whether Keycloak imports users into its own database or reads them on demand, and decide whether the directory or Keycloak owns each attribute.

Identity brokering is a different mechanism. It delegates login to another OIDC or SAML provider rather than reading a user store directly.

Sessions, Tokens and Clustering

Keycloak distinguishes a user session from the client sessions beneath it. A user signed into several applications can have one SSO user session and several client sessions. An authentication session holds state while login is still in progress; it is not the same object as an established user session.

Under the defaults described in the current caching guide, established user and client sessions are persisted in the database and loaded into embedded caches on demand. Those two caches default to 10,000 entries per node and one owner per entry. Evicting an entry from a cache therefore differs from ending the underlying session.

Use the deployment’s actual cache configuration when estimating what realm sessions cost in heap. The Keycloak memory and heap sizing calculator models session counts and stated assumptions; it does not calculate login-rate CPU requirements or enforce realm session limits.

Realm-Level Token Lifespans and Session Timeouts

Realm settings separates Tokens from Sessions. Access Token Lifespan controls how long an access token remains valid. SSO Session Idle controls inactivity, while SSO Session Max sets an outer lifetime for the user session. A refresh request can renew the idle timer; it does not remove the maximum lifetime.

Client Session Idle and Client Session Max apply to an application’s client session. The administration guide describes client overrides and inheritance from realm SSO values where a client timeout is left at zero. Review overrides when one application signs users out sooner than another.

Setting Decision it controls
Access Token Lifespan How long an issued access token is valid
SSO Session Idle How long the user session may be inactive
SSO Session Max The outer lifetime of the user session
Client Session Idle / Max The application’s client-session time bounds
Offline Session Idle / Max Separate lifetime rules for offline access

Shorter access tokens can reduce the period an already issued token remains usable, while clients maintaining access need to refresh more often. Ending a Keycloak session does not guarantee immediate rejection of an existing JWT by an API that validates it locally. Document logout and token validation behavior together instead of treating a short idle timeout as token revocation.

Offline access needs separate review. Its session rules differ from ordinary SSO, and the maximum lifetime depends on whether Offline Session Max Limited is enabled. Inventory applications that request offline access before changing those settings.

Concurrent Sessions: Limits Are an Authentication Policy

The User Session Count Limiter authenticator caps sessions per user, realm-wide or per client, and either rejects a new session or ends the oldest one. It goes in a copied authentication flow after the user is identified, and it is not a total realm capacity limit.

Realm Export and Import for Promotion Between Environments

Keycloak’s import and export guide supports JSON realm export, with --users skip to leave users out, but says “exported data does not include user and admin events, persisted sessions, workflow state or revoked tokens,” so it is not a full backup. Stopping all nodes is “recommended” before kc.sh export and “required” before an overriding kc.sh import, and startup --import-realm skips a realm that already exists. Issuer mismatches after promotion are a hostname problem, covered in Keycloak hostname and proxy errors.

Where to Go Next

Three follow-on questions come up almost immediately after the concepts above are settled:

FAQ

Is a Keycloak realm the same as a tenant?

Usually, yes. Keycloak’s getting-started guide calls a realm equivalent to a tenant, since each keeps its own users, clients and login policy. For B2B products where many customer companies share the same applications, Organizations, fully supported since Keycloak 26, provide multi-tenancy inside one realm instead of one realm per customer.

Can a user log in to more than one Keycloak realm?

Not with a single account. Realms are isolated, so an account in one realm does not exist in another, and each realm keeps its own SSO sessions. To reuse one set of credentials, configure identity brokering: register the first realm as an OpenID Connect identity provider in the second, and users can log in through it.

How do I find my Keycloak realm’s issuer URL?

Take the server’s public base URL and append /realms/ plus the realm name, for example https://sso.example.com/realms/myrealm. Confirm it by opening /realms/myrealm/.well-known/openid-configuration, whose discovery document lists the issuer and every endpoint. If the issuer shows the wrong host or scheme, fix the hostname and proxy settings, not the application.

How many realms can Keycloak handle?

It depends on version and cache sizing rather than a fixed limit. An October 2025 update to the GitHub discussion on realm scalability says that with Keycloak 26.4 it should be fine to run more than 1,000 realms as long as the realm cache keeps being increased. That cache defaults to 10,000 entries per the caching guide, resized with --cache-embedded-realms-max-count.

Sources

  1. Keycloak — Server Administration Guide: realms, sessions and client scopes
  2. Keycloak — Importing and exporting realms
  3. Keycloak — Configuring distributed caches
  4. Keycloak — Getting started with Docker
  5. Keycloak — Securing applications and services with OpenID Connect
  6. Keycloak — OAuth identity and authorization chaining across domains
  7. Keycloak documentation source — Admin CLI
  8. Keycloak documentation source — Organizations introduction
  9. Keycloak — Keycloak 26.0.0 released
  10. keycloak/keycloak GitHub discussion #11074 — Improved scalability over number of realms
  11. Keycloak — Running Keycloak in a container

Related