> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/ably/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Channels Overview

Channels are used to separate messages into different topics. They are the building block of creating a realtime application using the publish-subscribe pattern. Channels are also the unit of security and scalability. Clients should only ever be provided the [capabilities](/docs/auth/capabilities) for channels that they should have access to.

[Messages](/docs/pubsub/messages/format) contain the data that a client is communicating, such as the contents of an individual chat message, or an event that has occurred, such as updated financial information.

With Pub/Sub you create a channel, subscribe to it, and then publish messages to it. Most other Ably features utilize channels, or a group of channels, to provide additional functionality to your realtime applications.

## Use a channel

To get started with implementing any feature, a client must first create or retrieve an instance of a channel. A channel is created, or an existing channel is retrieved from the `Channels` collection. You can only connect to one channel in a single operation.

Channels are identified by their unique name. The following restrictions apply to when naming a channel:

* Channel names are case sensitive
* They can't start with `[` or `:`
* They can't be empty
* They can't contain newline characters

While Ably doesn't limit the length of channel names, keeping them under 2048 characters is recommended, since some older browsers have trouble with long URLs.

Use the [`get()`](/docs/api/realtime-sdk/channels#get) method to create or retrieve a channel instance:

<Code>
  ```realtime_javascript theme={null}
  const channel = realtime.channels.get('my-channel');
  ```

  ```realtime_nodejs theme={null}
  const channel = realtime.channels.get('my-channel');
  ```

  ```realtime_java theme={null}
  Channel channel = realtime.channels.get("my-channel");
  ```

  ```realtime_csharp theme={null}
  IRealtimeChannel channel = realtime.Channels.Get("my-channel");
  ```

  ```realtime_ruby theme={null}
  channel = realtime.channels.get('my-channel')
  ```

  ```realtime_python theme={null}
  channel = realtime.channels.get('my-channel')
  ```

  ```realtime_swift theme={null}
  let channel = realtime.channels.get("my-channel")
  ```

  ```realtime_go theme={null}
  channel := realtime.Channels.Get("my-channel")
  ```

  ```rest_javascript theme={null}
  const channel = rest.channels.get('my-channel');
  ```

  ```rest_nodejs theme={null}
  const channel = rest.channels.get('my-channel');
  ```

  ```rest_java theme={null}
  Channel channel = rest.channels.get("my-channel");
  ```

  ```rest_python theme={null}
  channel = rest.channels.get('my-channel')
  ```
</Code>

<Aside data-type="note">
  Although Ably recommends that you use channels to distribute work more evenly across the cluster, there is an [associated cost](/docs/platform/pricing) for a high number of channels.

  Don't use different channels just to indicate different types of data, or different events, if all messages are going to the same set of clients. Use a single channel and distinguish between them using a different message `name`.
</Aside>

## Channel namespaces

Channels can be grouped together into a namespace. This enables you to apply operations to a namespace rather than each individual channel within it.

A namespace is the first part of a channel name up to the first colon (`:`). If a channel name does not contain a colon, the namespace is the entire channel name. For example, the following channels are all part of the 'customer' namespace:

* `customer`
* `customer:tracking-id`
* `customer:order:update`

Channel namespaces have the same restrictions as those listed for channels. Additionally they cannot contain the wildcard character `*`.

Use channel namespaces to apply operations to all channels within that group, such as [capabilities](/docs/auth/capabilities), [channel rules](#rules) and [integrations](/docs/platform/integrations).

<Aside data-type="note">
  Namespaces are not required to refer to a group of channels within a [capability](/docs/auth/capabilities). A resource specifier, such as `foo:*`, a glob expression, will match a channel named `foo:bar`, even without a `foo` namespace.
</Aside>

## Channel options

[Channel options](/docs/channels/options) are used to customize the functionality of channels. This includes enabling features such as [encryption](/docs/channels/options/encryption) and [deltas](/docs/channels/options/deltas), or for a client to retrieve messages published prior to it attaching to a channel using [rewind](/docs/channels/options/rewind).

## Channel rules

Channel rules can be used to enforce settings for specific channels, or channel namespaces. They can be broadly categorized into three different types:

* For message storage
* For client security and identification
* To enable features for a channel or namespace

The channel rules related to message storage are:

| Rule                 | Description                                                                                                                                                                                                                                                             |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Persist last message | If enabled, the very last message published on a channel will be stored for a year. This message is retrievable using [rewind](/docs/channels/options/rewind) by attaching to the channel with `rewind=1`.                                                              |
| Persist all messages | If enabled, all messages published on a channel will be stored according to the storage rules for your account. This is 24 hours for free accounts and 72 hours for paid accounts. Messages stored in this manner are accessible using [history](/docs/pubsub/history). |

The channel rules related to security and client identity are:

| Rule       | Description                                                                                                                                                       |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Identified | If enabled, clients will not be permitted to use matching channels unless they are [identified](/docs/auth/identified-clients) (they have an assigned client ID). |
| TLS only   | If enabled, only clients who have connected to Ably over TLS will be allowed to use matching channels.                                                            |

To set a channel rule in the Ably dashboard:

1. Sign in to your Ably account.
2. Select an app.
3. Go to **Settings** tab.
4. Click **Add new rule**.
5. Select channel name or namespace to apply rules to.
6. Check required rules.

## Next steps

* Learn how to [publish messages](/docs/pubsub/channels/publish)
* Learn how to [subscribe to messages](/docs/pubsub/channels/subscribe)
* Explore [channel options](/docs/channels/options)
* Understand [message format](/docs/pubsub/messages/format)
