<p>A simple Bitcoin wallet consists on one of more pairs of public and private keys (I'm saying simple here as some wallet structure allow for deterministic public key generations and private keys that can only spend part of the wallet, but the principle with public/private keys remains the same). The "link" to Bitcoin initially happens during block generation where a certain amount of Bitcoin is generated and sent to the miner's public address; this is merely a record in the blockchain. Then these coins can be sent to other public addresses using transactions.</p>

<p>The most simple transaction has one input and one output; i.e. it spends coins from one source address to one destination address. To be valid, the amount of output coins must not exceed the amount of input coins, and to be verified the output address hash is signed by the input address' private key.</p>

<p>In real world though, wallets balances become the sum of all inputs to that wallet, so when you make a transaction the software will select the desired number of inputs to get a sum equal of greater to the desired transaction output + fee. If the amount exceeds what you want to spend, the remainder can be send back to one of the input address or even a new address of your wallet, so you basically send yourself the exceeding amount of Bitcoins. Any unspent amount in the transaction is considered fee and is collected by the miner generating the block.</p>

<p>Transactions can also be much more complex; Bitcoin allows for a very powerful scripting system that can make transactions spendable in many ways. You can read more about bitcoin transactions and scripting system here:</p>

<p><a href="https://en.bitcoin.it/wiki/Transactions" rel="noreferrer">https://en.bitcoin.it/wiki/Transactions</a></p>

<p><a href="https://en.bitcoin.it/wiki/Script" rel="noreferrer">https://en.bitcoin.it/wiki/Script</a></p>

<p>When you send out a transaction, it is relayed to the network for inclusion in a block if it passes common rules for transactions (validity, fee, size, etc.). A miner will eventually pick your transaction and include it a block (the transactions are actually included in a merkle tree whose root hash is in in the block header - the block header hash is the proof of work that has to match the difficulty requirement for the block).</p>

CC BY-SA 3.0
2014-01-06T17:01:25.740Z
2015-03-13T16:11:21.813Z
2015-03-13T16:11:21.813Z
Thomas Guyot-Sionnest
<p>Thomas' answer is correct, but I think an easy version may be appreciated as well.</p>

<p>I suppose you know the concept of <a href="https://en.wikipedia.org/wiki/Public-key_cryptography" rel="noreferrer">public key cryptography</a>? If you don't, here is a very short explanation (or read the wikipedia page): Public key cryptography (as used in Bitcoin), allows you to hand people a public key and use the corresponding private key to prove the ownership. So you can create any random private key (keep it secret) and calculate the corresponding public key (give it out to public for verification). Using this private key, you can sign a message and other people can verify that you own the private key by using your public key.</p>

<p>So, applied to Bitcoin.</p>

<p>A Bitcoin address is just a shorthand notation for a public key. When someone makes a transaction to an address, he states that <em>"I give the right to spend this money to the person who owns the private key corresponding to this address"</em>.
The person who has received this transaction will in turn be able to spend the transaction by signing the transaction using his private key. With this signature he can prove that he owns the key, without disclosing it. Others can verify the signature using the public key.</p>

<p>As for the second part of your question, it gets a little more advanced. An easy way of viewing it is that every transaction takes a number of inputs and generates a number of outputs. Inputs in this case are outputs from previous transactions. For each input, the user will have to provide verification he is allowed to spend that output by adding a signature.</p>

CC BY-SA 3.0
2014-01-06T18:51:08.260Z
2016-09-06T23:09:01.860Z
2016-09-06T23:09:01.860Z
Steven Roose
<p>I understand that all the Bitcoin protocol is based on an asymmetric cryptography. </p>

<p>A user gets 2 keys (public and private). How do these keys connect to the Bitcoins?</p>

<p>How are the keys are related to the wallet? How can I decide how many Bitcoins to transfer when using my private key?</p>

<wallet><private-key><public-key>
How are public and private keys related to the wallet?
Sean Black
# How are public and private keys related to the wallet?

(Asked by: username_0 on 2014-01-06)

I understand that all the Bitcoin protocol is based on an asymmetric cryptography.

A user gets 2 keys (public and private). How do these keys connect to the Bitcoins?

How are the keys are related to the wallet? How can I decide how many Bitcoins to transfer when using my private key?

**Tags:** wallet, private-key, public-key


---

## 2 answers

### Answer by username_2 on 2014-01-06. Score: 23 | Accepted answer

username_1' answer is correct, but I think an easy version may be appreciated as well.

I suppose you know the concept of [public key cryptography](https://en.wikipedia.org/wiki/Public-key_cryptography)? If you don't, here is a very short explanation (or read the wikipedia page): Public key cryptography (as used in Bitcoin), allows you to hand people a public key and use the corresponding private key to prove the ownership. So you can create any random private key (keep it secret) and calculate the corresponding public key (give it out to public for verification). Using this private key, you can sign a message and other people can verify that you own the private key by using your public key.

So, applied to Bitcoin.

A Bitcoin address is just a shorthand notation for a public key. When someone makes a transaction to an address, he states that *"I give the right to spend this money to the person who owns the private key corresponding to this address"*.
The person who has received this transaction will in turn be able to spend the transaction by signing the transaction using his private key. With this signature he can prove that he owns the key, without disclosing it. Others can verify the signature using the public key.

As for the second part of your question, it gets a little more advanced. An easy way of viewing it is that every transaction takes a number of inputs and generates a number of outputs. Inputs in this case are outputs from previous transactions. For each input, the user will have to provide verification he is allowed to spend that output by adding a signature.


---

### Answer by username_1 on 2014-01-06. Score: 7

A simple Bitcoin wallet consists on one of more pairs of public and private keys (I'm saying simple here as some wallet structure allow for deterministic public key generations and private keys that can only spend part of the wallet, but the principle with public/private keys remains the same). The "link" to Bitcoin initially happens during block generation where a certain amount of Bitcoin is generated and sent to the miner's public address; this is merely a record in the blockchain. Then these coins can be sent to other public addresses using transactions.

The most simple transaction has one input and one output; i.e. it spends coins from one source address to one destination address. To be valid, the amount of output coins must not exceed the amount of input coins, and to be verified the output address hash is signed by the input address' private key.

In real world though, wallets balances become the sum of all inputs to that wallet, so when you make a transaction the software will select the desired number of inputs to get a sum equal of greater to the desired transaction output + fee. If the amount exceeds what you want to spend, the remainder can be send back to one of the input address or even a new address of your wallet, so you basically send yourself the exceeding amount of Bitcoins. Any unspent amount in the transaction is considered fee and is collected by the miner generating the block.

Transactions can also be much more complex; Bitcoin allows for a very powerful scripting system that can make transactions spendable in many ways. You can read more about bitcoin transactions and scripting system here:

<https://en.bitcoin.it/wiki/Transactions>

<https://en.bitcoin.it/wiki/Script>

When you send out a transaction, it is relayed to the network for inclusion in a block if it passes common rules for transactions (validity, fee, size, etc.). A miner will eventually pick your transaction and include it a block (the transactions are actually included in a merkle tree whose root hash is in in the block header - the block header hash is the proof of work that has to match the difficulty requirement for the block).


---

