# affinity mask

> Bitmask of the CPUs this instance's schedulers may use; 0 lets Windows place the threads.

Source: https://sqlly.app/sql-configuration/sql-server/affinity-mask
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).

**Default**

`0 (Windows decides)`

**Range**

0, or a bitmask over the instance's CPUs

**Restart needed**

No

**Default checked on**

SQL Server 2025

## What it does

Each set bit names a CPU for SQL Server and each clear bit takes it away: on an 8-CPU system, 38 (0x26) is processors 1, 2 and 5. Affinity support for 33 to 64 processors needs a 64-bit OS, and above 64 CPUs the bitmask route gives out; ALTER SERVER CONFIGURATION SET PROCESS AFFINITY is the clearer tool anyway. On SQL Server Express the change takes effect only after a restart.

## Default value

`0 (Windows decides)`. 0 (SQL Server 2025). A nonzero value turns thread placement over to SQL Server.

## Check the current value

```
SELECT name, value, value_in_use, minimum, maximum, is_dynamic, is_advanced
FROM sys.configurations
WHERE name = 'affinity mask';

-- EXEC sp_configure 'affinity mask'; also works, but only while show advanced options is 1;
-- otherwise it fails with Msg 15123 because this is an advanced option.
```

## Change it

```
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'affinity mask', 38;
RECONFIGURE;
```

No restart: it takes effect when RECONFIGURE runs (sys.configurations.is_dynamic = 1). It is an advanced option, so show advanced options must be on to change it.

## When to change it

Deliberate core pinning only, such as keeping a co-located engine on its own cores or shrinking a licensed footprint. For workload isolation, Resource Governor fits better, and ALTER SERVER CONFIGURATION reads clearer than a bitmask.

## What can go wrong

A miscounted bitmask shrinks the scheduler pool silently: CPUs you meant to include end up excluded, worker threads crowd onto the rest, and the symptom is generic THREADPOOL pressure with no error naming the cause. A CPU set in both this mask and the affinity I/O mask is a conflict the engine does not allow, so compute the bits once and keep them in one place.

## Questions about affinity mask

### What is the default value of affinity mask in SQL Server?

0 (Windows decides). 0 (SQL Server 2025). A nonzero value turns thread placement over to SQL Server.

### Does changing affinity mask require a restart?

No. No restart: it takes effect when RECONFIGURE runs (sys.configurations.is_dynamic = 1). It is an advanced option, so show advanced options must be on to change it.

### When should I change affinity mask?

Deliberate core pinning only, such as keeping a co-located engine on its own cores or shrinking a licensed footprint. For workload isolation, Resource Governor fits better, and ALTER SERVER CONFIGURATION reads clearer than a bitmask.

Back to all [SQL Server settings](https://sqlly.app/sql-configuration/sql-server), or check the [SQL Server manual](https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/server-configuration-options-sql-server) for every option.

## Related SQL Server settings

- [`max worker threads` Size of the worker thread pool; 0 sizes it from the CPU count.](https://sqlly.app/sql-configuration/sql-server/max-worker-threads)
- [`lightweight pooling` Switch the engine's worker scheduling from thread mode to fiber mode.](https://sqlly.app/sql-configuration/sql-server/lightweight-pooling)
- [`max degree of parallelism` Most schedulers one parallel query operator may use; 0 means all.](https://sqlly.app/sql-configuration/sql-server/max-degree-of-parallelism)

## Related on SQLly

- [Finding what burns CPU on a database server Performance guide](https://sqlly.app/sql-performance/high-cpu)
- [SQL Server query performance troubleshooting Performance guide](https://sqlly.app/sql-performance/sql-server)
