# How to set Q value

**URL:** https://openfhe.discourse.group/t/how-to-set-q-value/2231
**Category:** Library Questions
**Tags:** questions, openfhe-help
**Created:** [December 8, 2025, 11:44am UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231 "2025-12-08T11:44:45Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![cappuccino](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cappuccino](https://openfhe.discourse.group/u/cappuccino)
#### Post date: [December 8, 2025, 11:44am UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231/1 "2025-12-08T11:44:45Z")

</div>

Hello developers!

I have a question about mod Q in CKKS.

I understand that the OpenFHE specifications determine a certain mod Q value when N is set.

And to set a large mod Q, I can use the `parameters.SetNumLargeDigits(dnum)` function, right?

I set the maximum `dnum` value at `N=2^15`, and obtained `log Q=810`.

Generally, with `N=2^15`, I can set a maximum of `log Q=881`, right?

Therefore, the `Q value` I set is `71` smaller.

I would like to obtain the maximum `mod Q` value. Is there any other way to set that value?

---

<div class="post-metadata">

### Author: ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)
#### Post date: [December 8, 2025, 4:47pm UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231/2 "2025-12-08T16:47:16Z")

</div>

The SetNumLargeDigits is a function that controls the decomposition performed during the relinearization phase (see the d\_\text{num} value in [https://eprint.iacr.org/2021/204.pdf](https://eprint.iacr.org/2021/204.pdf)). It controls the magnitude of the additional modulus P if HYBRID key switching is used. I am not aware of how that deals with the main modulus Q.

---

<div class="post-metadata">

### Author: ![cappuccino](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cappuccino](https://openfhe.discourse.group/u/cappuccino)
#### Post date: [December 9, 2025, 11:31am UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231/3 "2025-12-09T11:31:59Z")

</div>

> [@narger](#):
>
> SetNumLargeDigits

Thank you for providing details about` SetNumLargeDigits`.

If anyone knows how to control `modulus Q`, please let me know.

---

<div class="post-metadata">

### Author: ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)
#### Post date: [December 9, 2025, 1:12pm UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231/4 "2025-12-09T13:12:33Z")

</div>

You can control Q by adjusting the multiplicative depth.

Generally speaking, you should not set Q manually. OpenFHE handles that based on the desired security level and functionality.

---

<div class="post-metadata">

### Author: ![cappuccino](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cappuccino](https://openfhe.discourse.group/u/cappuccino)
#### Post date: [December 11, 2025, 4:17am UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231/5 "2025-12-11T04:17:45Z")

</div>

Following your reply, I tried experimenting with the following parameter settings, but received an error telling me to increase the order N.

This code has `ring Dimension=2^15`, `q_0 size=59`, `q_i size=50`, and `depth=16`. With this order, modulus Q should be able to be used up to 881, so 59+50\*16=859, and this code should not result in an error.

Why did this occur?

code:

```auto
#define PROFILE

#include "openfhe.h"

using namespace lbcrypto;

int main(int argc, char* argv[]) {
    CCParams<CryptoContextCKKSRNS> parameters;

    SecretKeyDist secretKeyDist = SPARSE_TERNARY;
    parameters.SetSecretKeyDist(secretKeyDist);

    parameters.SetSecurityLevel(HEStd_128_classic);
    parameters.SetRingDim(1 << 15);

    parameters.SetKeySwitchTechnique(HYBRID);

    ScalingTechnique rescaleTech = FIXEDMANUAL;
    usint dcrtBits = 50;
    usint firstMod = 59;

    parameters.SetScalingModSize(dcrtBits);
    parameters.SetScalingTechnique(rescaleTech);
    parameters.SetFirstModSize(firstMod);

    usint depth = 16;
    parameters.SetMultiplicativeDepth(depth);

    CryptoContext<DCRTPoly> cryptoContext = GenCryptoContext(parameters);

    std::cout << cryptoContext->GetModulus().GetMSB() << std::endl;

    std::cout << depth << std::endl;
}

```

error message:

```auto
openfhe-development/src/pke/lib/scheme/ckksrns/ckksrns-parametergeneration.cpp:l.149:ParamsGenCKKSRNSInternal(): The specified ring dimension (32768) does not comply with HE standards recommendation (65536).

```

---

<div class="post-metadata">

### Author: ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)
#### Post date: [December 11, 2025, 1:36pm UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231/6 "2025-12-11T13:36:55Z")

</div>

Consider that by fixing HYBRID key switching, the modulus is extended from \log(Q) to \log(QP), where the magnitude of P depends on the decomposition of the ciphertext (d\_\text{num} value). See page 29 of [https://eprint.iacr.org/2021/204.pdf](https://eprint.iacr.org/2021/204.pdf)

---

<div class="post-metadata">

### Author: ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)
#### Post date: [December 11, 2025, 4:06pm UTC](https://openfhe.discourse.group/t/how-to-set-q-value/2231/7 "2025-12-11T16:06:19Z")

</div>

To add more info to @narger’s response.

There are other moduli used internally in OpenFHE, and P is one of them. The totatlity of \log\_2{}QP is used to define the security level. Note also that Q itself might include additional moduli more than just (1+depth) moduli depending.

OpenFHE automatically selects a specific ring dimension to ensure the desired security level is met for the needed functionality (which is mostly defined by the specified scheme, circuit depth, and moduli sizes).

So in your case, you need to decrease the depth and/or the dcrtBits if you want to maintain the ring dimension at 2^{15}.  
Or you can select a different key switching algorithm that requires smaller P and that by itself is a topic of its own.
