<p>A Varint is a <a href="https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer" rel="nofollow noreferrer">Variable Length Integer</a>, and can be up to 9 bytes in total</p>

<p>It is usually only one byte, which can represent numbers 0-252. 253-255 (0xFD-0xFF) are used as markers for the next three lengths.</p>

<pre><code>Marker    Payload
None      1 byte of integer data
0xFD      0xFD followed by two bytes of integer data
0xFE      0xFE followed by four bytes of integer data
0xFF      0xFF followed by eight byes of integer data
</code></pre>

<p>Each marker indicates how to interpret the upcoming bytes.</p>

CC BY-SA 4.0
2020-04-14T11:12:04.183Z
So to have a better understanding: At most this field can be: FFFFFFFFFFFFFFFFFF, which represents 1.844674407371E+19 
 many inputs in the transaction, right? (first byte for representation and others for the input count)
Efe
CC BY-SA 4.0
2020-04-14T12:54:38.693Z
@EfeCini That's right - you will hit the block's SIGOPS and size limits far before you hit a encoding limit for the number of inputs
Raghav Sood
CC BY-SA 4.0
2020-04-14T13:56:57.830Z
Similarly PUSHDATA4 as an opcode is impossible to use.
Claris
CC BY-SA 4.0
2020-04-14T13:57:30.393Z
Except on legacy transactions.
Claris
CC BY-SA 4.0
2020-04-14T10:30:08.203Z
2020-04-14T10:30:08.203Z
Raghav Sood
<p>I know that we parse a transaction in bytes. So there are 2 quesions that I search for the answers of:</p>

<p>1- Can VarInt field -that gives the number of inputs in a transaction- be more than 2 hex digits(2 Hex = 8 bits = 1 byte)? I am asking this to be sure that it is not fixed size. We know that 2^8 = max 256 and I am pretty sure that there can be more than 256 inputs in a tx.</p>

<p>2- If it is not a fixed size field how do we know where number of inputs field ends or prevTx field starts?
<a href="https://i.sstatic.net/9yWAk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9yWAk.png" alt="Transaction"></a></p>

CC BY-SA 4.0
2020-04-14T10:29:52.190Z
Does [this](https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer) answer your question? Or [this code](https://github.com/bitpay/bitcore/blob/785fbe5f5065d1dd78c328ce5ec0296ec3ecce69/packages/bitcore-lib/lib/encoding/bufferwriter.js#L110)?
MCCCS
<transactions><transaction-input>
How to know where number of inputs field ends in a transaction if it is not a fixedsize field?
Efe
# How to know where number of inputs field ends in a transaction if it is not a fixedsize field?

(Asked by: username_0 on 2020-04-14)

I know that we parse a transaction in bytes. So there are 2 quesions that I search for the answers of:

1- Can VarInt field -that gives the number of inputs in a transaction- be more than 2 hex digits(2 Hex = 8 bits = 1 byte)? I am asking this to be sure that it is not fixed size. We know that 2^8 = max 256 and I am pretty sure that there can be more than 256 inputs in a tx.

2- If it is not a fixed size field how do we know where number of inputs field ends or prevTx field starts?
[![Transaction](https://i.sstatic.net/9yWAk.png)](https://i.sstatic.net/9yWAk.png)

**Tags:** transactions, transaction-input

> **Comments:**
> **username_1**: Does [this](https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer) answer your question? Or [this code](https://github.com/bitpay/bitcore/blob/785fbe5f5065d1dd78c328ce5ec0296ec3ecce69/packages/bitcore-lib/lib/encoding/bufferwriter.js#L110)?  

---

## 1 answers

### Answer by username_2 on 2020-04-14. Score: 1 | Accepted answer

A Varint is a Variable Length Integer, and can be up to 9 bytes in total
It is usually only one byte, which can represent numbers 0-252. 253-255 (0xFD-0xFF) are used as markers for the next three lengths.
Marker    Payload
None      1 byte of integer data
0xFD      0xFD followed by two bytes of integer data
0xFE      0xFE followed by four bytes of integer data
0xFF      0xFF followed by eight byes of integer data

Each marker indicates how to interpret the upcoming bytes.

> **Comments:**
> **username_0**: So to have a better understanding: At most this field can be: FFFFFFFFFFFFFFFFFF, which represents 1.844674407371E+19   many inputs in the transaction, right? (first byte for representation and others for the input count)  
> **username_2**: @username_0Cini That's right - you will hit the block's SIGOPS and size limits far before you hit a encoding limit for the number of inputs  
> **username_3**: Similarly PUSHDATA4 as an opcode is impossible to use.  
> **username_3**: Except on legacy transactions.  

---

