(NOTE: THIS POST HAS BEEN CORRECTED! ALL THE PEOPLE WHO AFTERWARDS SAY THAT IT GAVE WRONG INFORMATION WERE RIGHT AND I WAS WRONG. I HAVE EDITED THIS TO BE CORRECT SO THAT IT WON'T MESS PEOPLE UP IN THE FUTURE. ALSO SEE THE TOP OF PAGE 5 FOR THE CORRECT PROCEDURE TO DETERMINE FEES WITHOUT THE RANTING ABOUT POOR DOCUMENTATION I DID BELOW.)
Let me see if I get this:
First you have to figure out how big your transaction is, using a formula that the wiki never tells you. It took hours of reading and guessing and searching the wiki to figure out what the formula is.
I will tell you now, but it took the rest of this post to figure it out. It's 12 bytes, plus 204 bytes per input, plus 32 bytes per output. If it's more than 256 inputs or outputs, add one byte. If there's anything even a little bit unusual about the "scripts" involved for any input or output, this formula is not valid. Remember that your transaction usually has at least one more output than is visible; this is because you don't usually have exact change, and the transaction must split at least one of your coins (and may consolidate others) to come back to you.
Second, figure out your transaction's "priority" using a stupidly complex formula that they don't tell you how to calculate.
The formula is given as priority = sum(input_value_in_base_units * input_age)/size_in_bytes.
But I use input value in millibitcoins instead, to save the bother of dealing with five unnecessary decimal positions.
In order to figure out what it means for a given transaction, you must first multiply the value of each input in millibitcoin times the number of days since it was paid to you, add all the products together to get a sum, convert the number of inputs/outputs in your transaction to size_in_bytes, then divide the sum by the size_in_bytes which they did not tell you how to calculate.
Your transaction is "free" if all of the following are true.
* it's smaller than 10,000 bytes. (but they didn't tell you how to figure that out)
* All the outputs are 0.01 BTC (currently around $8) or larger.
* priority is greater than 576. (and you couldn't know that without being able to figure out the size)
(Note: when dev guys talk about "priority" they'll add five zeros onto the end. I've simplified the formula so you don't have to).
Your transaction is also "free" if its priority is higher than the priority of all other transactions in the block except for enough other transactions to make 27,000 bytes (BUT YOU HAVE NO IDEA WHETHER OTHER HIGHER-PRIORITY TRANSACTIONS ARE GOING INTO THIS BLOCK, AND THEY DON'T TELL YOU HOW TO CALCULATE THE SIZE IN BYTES OF YOUR TRANSACTION OR GUESS AT THE SIZE IN BYTES OF OTHER TRANSACTIONS OR TELL YOU WHAT IS TYPICAL NUMBER OF FREE TRANSACTIONS YOU'RE COMPETING FOR SPACE WITH).
Now, if your transaction qualifies as "free" it will be propagated across the network without fees. But the reference client will not spend more than 15,000 bytes per minute on propagating such transactions (AND YOU HAVE NO WAY OF KNOWING HOW THAT AFFECTS RELIABILITY AND SPEED WITHOUT KNOWING WHAT THE TYPICAL TRAFFIC IN FREE TRANSACTIONS IS AND/OR HAVING THE RESULTS OF EMPIRICAL MEASUREMENTS).
If your transaction is not "free" you had better add a transaction fee. To figure out the transaction fee you need to find the size of your transaction, round it up to the next even multiple of a thousand, then multiply the result by
1 0.1 microbitcoins.
And the final gotcha: if you have to add another input, or more than one other input, in order to cover the transaction fee, then the size of your transaction in bytes has changed, and you must start over and figure out your fee again. And if you get your fee even one Satoshi wrong, then most clients will just drop your transaction on the floor instead of propagating it and you'll have absolutely no benefit from the fee you did add. If your transaction confirms at all it may take days, and the fee will have been a complete waste of your money.
********** STOP READING HERE UNLESS YOU WANT TO KNOW HOW I FIGURED OUT HOW TO FIND THE SIZE OF TRANSACTIONS *******
Does that about sum it up? Clear as mud? What's that? Still have unanswered questions about the size of your transaction which was the first thing you had to figure out?
Okay, going to
https://en.bitcoin.it/wiki/Transactions, we can start to figure out how to find the size of a transaction in bytes.
it is 8 bytes, plus the size of the input count, plus the size of the output count, plus the number of inputs times the size of an input, plus the number of outputs times the size of an output. Nice and simple, right? questions answered, right?
oh, wait; THEY DON'T TELL YOU ON THAT PAGE WHAT THE SIZE OF AN INPUT OR THE SIZE OF AN OUTPUT OR THE SIZE OF THE INPUT COUNT OR THE SIZE OF THE OUTPUT COUNT IS.
Okay, going to
https://en.bitcoin.it/wiki/Protocol_specification#Variable_length_integer we find the size of the input count and the size of the output count. You're going to laugh. If the number of inputs is less than 0xfd it's one byte. Add another 2 bytes if the number of inputs is more than 0xfd and *another* two bytes if the number of inputs is more than 0xffff. The number of outputs is given the same way. For those who don't speak Martian, those numbers are 0xfd=254 and 0xffff = 65536. Because Martians count in base 16, that's why.
For any "normal" transaction, call that 12 bytes plus the number of inputs times the size of an input plus the number of outputs times the size of an output. But if you're using "dust" (more than 254 inputs) it can be 14 bytes rather than 12, so keep that in mind.
The size of an input is given at
https://en.bitcoin.it/wiki/Transactions#general_format_.28inside_a_block.29_of_each_input_of_a_transaction_-_Txin.
It's 40 bytes plus another Martian number plus the size of the in-script.
The size of an output is given right below it. It's 8 bytes plus another Martian number plus the size of the out-script.
And the size of the Martian numbers depends on the size of the in-script and the out-script. BUT THEY DON'T TELL YOU ON THAT PAGE HOW TO FIND THE LENGTH OF THE SCRIPT.
Okay, it looks like scripts are almost universally less than 0xfd long, so the Martian numbers are going to be one byte long unless there is something really weird going on. That makes inputs 41 bytes plus the size of the in-script, and outputs 9 bytes plus the size of the out-script.
Going to
https://en.bitcoin.it/wiki/Script, we find that the "standard" script consists of
OP_DUP OP_HASH160
OP_EQUALVERIFY OP_CHECKSIG. all of the OP_whatever are 1 byte, so this is 4 bytes plus the length of a pubKeyHash which is 20 bytes. Total is 24 bytes.
And it doesn't say ANYWHERE I can find whether this is the standard for an in-script or the standard for an out-script. You really need to know in order to figure out how big your transaction is in bytes. According to their example however, which I can read because I can read Martian, this has to be the standard for an out-script. So each "output" of your transaction, if it's a normal transaction, is 32 bytes - a nice round number, in Martian.
Now, an in-script is mentioned nowhere in the whole damn wiki, except on the page that says you need to know how big it is to figure out the size of your transaction and then doesn't define it. However, back on the Transactions page in an earlier link, it says that the "ScriptSig" is the "first half of a script" and that's the only mention of a script anything in the inputs of a transaction so it's pretty much got to be it. It also says that a "ScriptSig" consists of a signature and a public key. Okay, great. The size of an input is 41 bytes plus the size of a signature plus the size of a public key. Going back to the protocol specification, we find out that the size of a signature is two 32-byte integers plus a prefix 04 (presumably one byte). So, probably 65 bytes. But it can be given in a "compressed form" where one of the 32-byte numbers is replaced by a "sign" telling whether it is even or odd. The "sign" is 0x2 or 0x3 - again presumably one byte, so the compressed form is 33 bytes. So a signature is either 33 or 65 bytes, and we don't know which, making our input 74 or 106 bytes plus the size of a public key. I couldn't find anything on the wiki defining the number of bytes in a public key, so that's a dead end. However, there is a transcript of a Martian conversation on the protocol specification page that actually mentions a scriptsig and says that it's 139 bytes long.
139 plus either 65 or 33 bytes is 204 bytes or 172 bytes. Neither of those is a particularly "round" number in Martian. Nor does it tell in English anywhere which of them you should use. But, when I searched for "33" there was nothing interesting on the wiki and when I searched for "65" I found the page https://en.bitcoin.it/wiki/OP_CHECKSIG with a transcript of a Martian statement where it actually checks an input signature, and that signature is in fact 65 bytes long. Taking that as the norm, we conclude that each input is then 204 bytes long.
So, after a lot of chasing and assumptions and guesswork and reading in Martian where it's not given in English, the formula for the size of your transaction is the following:
12 bytes, plus 204 bytes per input, plus 32 bytes per output.
I'd put this formula into the damn wiki, except they want me to pay ten bucks for the privilege.
Okay, not spreading "misinformation" any more.