# Gateway weight (/docs/reference/gateway-weight)

When more than one active gateway can take a payment, Comecero picks one at random, weighted by each gateway's **weight**. A gateway can take a payment when it handles the payment method type, the currency and, for a card, the card brand.

Set the weight on the gateway in the dashboard under **Gateways**, or in the `weight` field of [Update a gateway](/api/gateways/update-gateway). The default is `1`.

## How the weight works [#how-the-weight-works]

The chance that a gateway is picked is its weight divided by the total weight of the gateways that can take the payment.

| Gateway | Weight | Share of payments |
|---|---|---|
| A | 100 | About half |
| B | 100 | About half |

| Gateway | Weight | Share of payments |
|---|---|---|
| A | 10 | About 1 in 11 |
| B | 100 | About 10 in 11 |

A gateway with weight `0` is a **backup**. It is picked only after every gateway with a weight above 0, for example when they declined the payment.

## Trying another gateway after a decline [#trying-another-gateway-after-a-decline]

When a card is declined and more than one gateway can take it, Comecero can try the next gateway in the weighted order. **Maximum Gateway Attempts** under **Settings > Payment** (`max_gateway_attempts` in [Update payment settings](/api/settings/update-payment-settings)) sets how many gateways to try in all. Set it to `1` to never try a second gateway. New accounts start at `2`.

## When the weight is not used [#when-the-weight-is-not-used]

- **A payment method locked to a gateway.** A saved card can be tied to the gateway that stored it, for example after that gateway updated the card number. That gateway goes first, even with weight `0`. A card saved on Comecero Express Payments can only be charged there.
- **Comecero Express Payments first.** When your account's own Comecero Express Payments gateways and Comecero's platform gateways can both take a payment, your Express gateways go first and the platform gateways are kept as backup.
- **A gateway you choose.** A secret or trusted token can send `gateway_id` on a payment to use that gateway instead of letting Comecero choose (not on accounts on the reseller model).
