# Why is my balance not equal to the sum of inbound, minus the sum of outbound and fees?

I expect to be able to calculate the balance of an account in this way: add up the value on all the incoming transactions, and subtract the value on all the outgoing transactions, then subtract all the fees paid.

When I use this method, though, I get a different balance from several other sources, like: `eth.getBalance(account)` and Etherscan. Why?

## An Example

I picked a random account that has this "issue."

All account transactions:

Let's rewrite these transaction values...

in python code:

``````inbound = ['10']
outbound = ['9', '0.92']
paid_fees = ['0.00045932', '0.010846898028', '0.00084084']
``````

Account Balance:

So when we calculate the sum, I expect to get the same as the balance that Etherscan shows:

Instead, I get `Decimal('0.067852941972')` from the following calculation:

``````from web3 import Web3

total = sum(Web3.toWei(income, 'ether') for income in inbound)
for ether_spent in outbound + paid_fees:
total -= Web3.toWei(ether_spent, 'ether')

total_ether = Web3.fromWei(total, 'ether')
print(total_ether)
``````

## What is this dark magic?

Did this account generate Ether out of thin air?

• This issue causes problems for exchanges, too, sometimes: ethereum.stackexchange.com/questions/4270/… Sep 15, 2017 at 20:32
• I had this problem myself before, it's very inconvenient when you are trying to run a business and the books don't balance! Something that needs to be improved in the crypto space!
Sep 15, 2017 at 22:08

Did this account generate Ether out of thin air?

No. Ethereum isn't broken, and neither are ENS or Etherscan. Although Etherscan could be clearer about what's happening here.

## So how do you get the real balance?

If you click into the most recent transaction issued by the account (the one with 0 outbound value), you see this:

Sorry it's awkwardly clipped. I'm trying to give a bit of privacy to this random person.

The first and third TRANSFER are being sent back to the account that issued the transaction. Although it's an outbound transaction, with 0 value, the account actually got Ether back! So what is the new balance?

``````from decimal import Decimal
real_ether_balance = total_ether + Decimal('0.02') + Decimal('0.0045')
``````

The real balance is: `Decimal('0.09235')`