DER Format

1 min read

The Distinguished Encoding Rules (DER) format is a defined standard which Bitcoin uses to encode ECDSA signatures. A signature consists of a random number called an r value, and the signature itself, called the s value. A typical Bitcoin signature is 71 bytes long, as a one byte sighash flag is appended to the DER signature, and these bytes are represented in hexadecimal format.

DER format begins with a prefix byte of 0x30, followed by the length of the signature. Next comes an 0x02 byte followed by the length of the r value, followed by the r value itself. Finally, an 0x02, the length of the s value, and the s value are added. For both r and s values, if the first byte is higher than 0x80, an additional 0x00 byte is prepended to the value. So, while r and s values are both 32 bytes long, they occasionally take up 33 bytes in DER format.