<p>To add to Chow's answer:</p>
<p>How sigops are counted changed with the activation of SegWit in 2017. For example, the sigop count in pre-SegWit scripts (P2PK, P2PKH, ...) was quadrupled from 1 to 4. See the sigops section in BIP-141: <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#sigops" rel="nofollow noreferrer">https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#sigops</a></p>

CC BY-SA 4.0
2024-03-22T13:03:11.157Z
2024-03-22T13:03:11.157Z
0xb10c
<p>Each <code>OP_CHECKSIG</code> and <code>OP_CHECKSIGVERIFY</code> is counted as 1 sigop.</p>
<p>Each <code>OP_CHECKMULTISIG</code> or <code>OP_CHECKMULTISIGVERIFY</code>, is counted as 20 sigops if they are found in an output or scriptSig and not part of a redeemScript, i.e. not P2SH.</p>
<p>If <code>OP_CHECKMULTISIG</code> or <code>OP_CHECKMULTISIGVERIFY</code> are in a redeemScript (i.e. it's P2SH), then the number of sigops is the number of public keys in the multisig redeemScript. If there is more than 16 public keys, then it is always accounted as 20.</p>
<p>For non-segwit inputs, these numbers are multiplied by 4, so 4 sigops for <code>OP_CHECKSIG</code> and <code>OP_CHECKSIGVERIFY</code>, and 80 sigops for <code>OP_CHECKMULTISIG</code> and <code>OP_CHECKMULTISIGVERIFY</code>.</p>
<p>However segwit inputs don't use these scripts explicitly. So a segwit input where the witness program is version 0 and the program is 20 bytes (i.e. P2WPKH), the number of sigops is 1. If the witness program is version 0 and the program is 32 bytes (i.e. P2WSH), the witnessScript is interpreted and its sigop count is as above as that uses the opcodes explicitly.</p>
<hr />
<p>So in your example transaction, the input spends a P2SH-P2WPKH and the output has an <code>OP_CHECKSIG</code>. Since the input is P2WPKH, it is counted as 1 sigop. The output as an <code>OP_CHECKSIG</code>, so that's another 1 sigop. However because that output is not a segwit output, its number of sigops is multiplied by 4. Thus the output is actually 4 sigops. Summing those is 1 + 4 = 5 sigops in the entire transaction.</p>

CC BY-SA 4.0
2019-07-19T07:10:56.937Z
Why is `OP_CHECKMULTISIG` and `OP_CHECKMULTISIGVERIFY` counted as 20 sigops if they are found in output?
rny
CC BY-SA 4.0
2023-04-10T10:56:50.900Z
"then the number of sigops is the number of public keys in the multisig redeemScript" -> Hmm if it's >16 then it's accounted as 20, if i remember correctly.
Antoine Poinsot
CC BY-SA 4.0
2018-01-07T03:44:36.087Z
2023-04-10T10:59:12.640Z
2023-04-10T10:59:12.640Z
Ava Chow
<p>How are sigops calculated on a transaction? For example in the (randomly selected) following transaction:</p>

<p><a href="https://btc.com/bc9384919ad5d08b2c66e31f29e7c63572c398a87631c03a4ce9e94ff1cbe62f" rel="noreferrer">https://btc.com/bc9384919ad5d08b2c66e31f29e7c63572c398a87631c03a4ce9e94ff1cbe62f</a></p>

<p>It says there were 5 sigops. What is the rule for calculating this number?</p>

<transactions><script><signature-operations>
How are sigops calculated?
Edward Kerstein
# How are sigops calculated?

(Asked by: username_0 on 2018-01-07)

How are sigops calculated on a transaction? For example in the (randomly selected) following transaction:

<https://btc.com/bc9384919ad5d08b2c66e31f29e7c63572c398a87631c03a4ce9e94ff1cbe62f>

It says there were 5 sigops. What is the rule for calculating this number?

**Tags:** transactions, script, signature-operations


---

## 2 answers

### Answer by username_2 on 2018-01-07. Score: 13 | Accepted answer

Each `OP_CHECKSIG` and `OP_CHECKSIGVERIFY` is counted as 1 sigop.

Each `OP_CHECKMULTISIG` or `OP_CHECKMULTISIGVERIFY`, is counted as 20 sigops if they are found in an output or scriptSig and not part of a redeemScript, i.e. not P2SH.

If `OP_CHECKMULTISIG` or `OP_CHECKMULTISIGVERIFY` are in a redeemScript (i.e. it's P2SH), then the number of sigops is the number of public keys in the multisig redeemScript. If there is more than 16 public keys, then it is always accounted as 20.

For non-segwit inputs, these numbers are multiplied by 4, so 4 sigops for `OP_CHECKSIG` and `OP_CHECKSIGVERIFY`, and 80 sigops for `OP_CHECKMULTISIG` and `OP_CHECKMULTISIGVERIFY`.

However segwit inputs don't use these scripts explicitly. So a segwit input where the witness program is version 0 and the program is 20 bytes (i.e. P2WPKH), the number of sigops is 1. If the witness program is version 0 and the program is 32 bytes (i.e. P2WSH), the witnessScript is interpreted and its sigop count is as above as that uses the opcodes explicitly.

---

So in your example transaction, the input spends a P2SH-P2WPKH and the output has an `OP_CHECKSIG`. Since the input is P2WPKH, it is counted as 1 sigop. The output as an `OP_CHECKSIG`, so that's another 1 sigop. However because that output is not a segwit output, its number of sigops is multiplied by 4. Thus the output is actually 4 sigops. Summing those is 1 + 4 = 5 sigops in the entire transaction.

> **Comments:**
> **username_3**: Why is `OP_CHECKMULTISIG` and `OP_CHECKMULTISIGVERIFY` counted as 20 sigops if they are found in output?  
> **username_4**: "then the number of sigops is the number of public keys in the multisig redeemScript" -> Hmm if it's >16 then it's accounted as 20, if i remember correctly.  

---

### Answer by username_1 on 2024-03-22. Score: 0

To add to username_2's answer:

How sigops are counted changed with the activation of SegWit in 2017. For example, the sigop count in pre-SegWit scripts (P2PK, P2PKH, ...) was quadrupled from 1 to 4. See the sigops section in BIP-141: <https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#sigops>


---

