There is no Leather mobile app at this time. Please only install Leather from leather.io or the Chrome Web Store by Google.

There is no Leather mobile app at this time. Please only install Leather from leather.io or the Chrome Web Store by Google.

There is no Leather mobile app at this time. Please only install Leather from leather.io or the Chrome Web Store by Google.

Back

What is a Bitcoin SegWit Address?

General Wallet Use

15 min

A Bitcoin address is a unique identifier that consists of a series of letters and numbers that can range between 34 and 62 characters that are used in Bitcoin transactions. Today's Bitcoin user has access to a variety of Bitcoin address types, and their emergence speaks to continued efforts to improve Bitcoin scalability.


This Leather Learn Center piece will primarily focus on one specific address type: Segregated Witness (SegWit) addresses. We will explain what SegWit addresses are and how they can be applied within a real-world setting.

Origins of the SegWit Bitcoin Address Format


SegWit addresses were introduced in 2017 along with the SegWit update and can be distinguished from other address types due to it starting with the number “3”. SegWit was designed for two specific purposes: fixing transaction malleability and raising the transaction capacity to increase block size.


Transaction malleability is a phenomenon in which the Transaction ID (txid) can change after a transaction has been confirmed but doesn’t invalidate the digital signature. This can occur because the txid is created when the transaction data is hashed, so any changes to the txid that do not invalidate the digital signature create malleability problems. The reason why this is such a major issue is that if someone tries to spend bitcoin they made from a previous transaction before it was confirmed, they must reference the txid of that previous transaction. However, if the txid changes because of transaction malleability, the reference will fail and the user won’t be able to spend that bitcoin.


SegWit was able to fix transaction malleability by separating the signature data (the witness data) from the transaction data, moving it instead to a different part of the blockchain. This means that txid is now calculated solely based on transaction data instead of both transaction and signature data. This major change meant that the txid could not be altered even if signature data changed, making it much easier for a user to reference back to the txid of a previous transaction before spending their BTC. Additionally, SegWit’s ability to separate the Witness data from transaction data also raised the transaction capacity to increase the block size by changing the limit of Bitcoin transactions from 1MB to 4MB. An increase in block size meant a decrease in transaction fees since more transactions could take place within a block.


While SegWit was originally met with pushback as some argued that Bitcoin would not be able to handle this massive increase in transactions that it would create, SegWit addresses have since become one of the most popular and efficient address types since its introduction in 2017. It has become so popular that it served as the basis for an even newer and more efficient address format: Native SegWit. Native SegWit was essentially designed to be an improvement upon original SegWit addresses as it is optimized in a way that results in an even smaller transaction size. That translates to an even more efficient use of block size and smaller transaction fees. Native SegWit also has made Bitcoin transactions more secure and user-friendly by making Native SegWit addresses case-insensitive and improving error detection on QR Code efficiency.

How is a SegWit Address Generated?


As we mentioned in our post about legacy Bitcoin addresses, most addresses are generated similarly: the creation of a Bitcoin wallet leads to the creation of a private and public key that are mathematically linked to each other, followed by the public key getting hashed into a Bitcoin address. The creation of SegWit addresses involves two different procedures, one for each type of SegWit address: Pay-to-Witness-PubKey-Hash (P2WPKH) and Pay-to-Witness-Script-Hash (P2WSH).


The main difference between P2WPKH and P2WSH is that P2WPKH was optimized for single-key transactions involving a single public key and private key while P2WSH was designed to utilize a wide range of more complex script conditions, making it ideal for more complicated transactions and use cases that cover more than single-key transactions.

Creating a P2WPKH SegWit address

The P2WPKH SegWit address is made by first putting the public key through the SHA256 algorithm, and the result is then used to calculate a 20-byte hash called the Public Key Hash (also known as Hash160). The version byte 0x00, which is the one for P2WPKH addresses, is then linked together with the Public Key Hash.


Once that’s done, a 4-byte checksum is calculated by hashing the combined data (version byte and Hash160) twice using the SHA256 algorithm. The first 4 bytes of the result of the double-hashing is then linked with the Public Key Hash. Finally, all this combined data (containing version byte, Public Key Hash, and checksum) is then encoded into the encoding scheme, Base58 (which was also discussed in the Legacy Address piece), and results in a P2WPKH SegWit Address.

Creating a P2WSH SegWit address

The creation process for the P2WSH SegWit address is slightly different as it requires a witness script, which is a series of conditions that must be met before the bitcoin within the address can be spent. The witness script is then hashed by the SHA256 algorithm, resulting in the Witness Script Hash which consists of 32-bytes. Additionally, the version byte 0x00 is linked with the Witness Script Hash and a checksum is calculated based on that combined value of data. The first 4 bytes of that calculation serve as the checksum and are linked with the version byte and Witness Script Hash.


Finally, the combined data consisting of the version byte, Witness Script Hash, and the checksum is encoded using the Base58, which then leads to the creation of a P2WSH SegWit address.

Comparing Addresses


When comparing legacy SegWit addresses with the other address formats, especially Native SegWit addresses, each has its advantages and characteristics, and it is ultimately up to each user to decide which type they want to use. For example, as mentioned previously, the Native SegWit has an even smaller transaction size than legacy SegWit, meaning that the Native SegWit more efficiently utilizes its block size and has smaller transaction fees than its predecessor.


However, as advantageous as these upgrades are, the downside is that Native SegWit addresses face certain compatibility issues as this address format is not universally accepted by all Bitcoin wallets because not all wallets have all the necessary software and infrastructure updates to adopt this newer format. Legacy SegWit addresses on the other hand not only have reduced transaction sizes and fees, though not as low as Native SegWit, but they are more universally accepted by most, if not all Bitcoin wallets. Legacy SegWit addresses’ compatibility with Bitcoin Wallets makes them much more reliable and secure methods for users to send and receive cryptocurrency.


Overall, these are all the vital points that you need to know about SegWit addresses. Since its introduction back in 2017, SegWit has proven to be a much-needed upgrade for Bitcoin and has quickly become a popular address for users thanks to its many advantages and real-world applications.


Connect to web3 applications built on Bitcoin with the Leather browser extension. Install Leather – the only wallet you need to tap into the multilayered Bitcoin economy – today.