TeachMeBitcoin

The DER Encoding Standard

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The DER Encoding Standard

Bitcoin signatures are not stored as raw bytes. Instead, they are wrapped in a standard called DER (Distinguished Encoding Rules). This ensures that different computer systems can parse the $r$ and $s$ values without ambiguity.

1. ASN.1 Structure

DER is a subset of ASN.1, a language used to define data structures. A Bitcoin signature in DER looks like this: 0x30 [TotalLen] 0x02 [rLen] [rData] 0x02 [sLen] [sData] [Sighash]

2. Why the length varies?

You may have noticed that Bitcoin signatures are usually 70, 71, or 72 bytes. This is because of how DER handles "Negative" numbers.

3. The Sighash Byte

At the very end of every DER signature is an extra byte called the Sighash Type (usually 0x01).

4. Example Breakdown

Raw Hex: 304502210089...022074...01

  1. 30: Start Sequence.

  2. 45: Total length (69 bytes).

  3. 02: Start Integer $r$.

  4. 21: Length of $r$ (33 bytes—includes an extra 00 padding).

  5. 0089...: The value of $r$.

  6. 02: Start Integer $s$.

  7. 20: Length of $s$ (32 bytes).

  8. 74...: The value of $s$.

  9. 01: Sighash ALL.

Byte Pattern Meaning
0x30 Signature Container
0x02 Integer Start
0x01 Sighash Type (at end)

In the next section, we will discuss Signature Malleability.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!