---
id: SI0055
title: "Program size and balance answers"
url: https://carbium.sh/library/si/program-size-and-balance-answers
collection: AI and blockchain
category: Plain-English chain queries
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Program size and balance answers

A program address and its programdata address are two accounts, each with its own length and balance. The script reads both, decodes the header, prices both sizes at the rent minimum and prints each command's pair with the arithmetic joining them.

## Two accounts behind one address

An upgradeable program lives in two accounts. The one at the address people share, the program account, is a stub: a 4-byte tag and the address of a second account. The code sits in that second account, called programdata. `solana account <address>` reads the account at the address you typed, so it reports the stub's length and the stub's balance. `solana program show <address>` follows the pointer and reports programdata: a data length and a balance that belong to the other account. Both commands answer correctly. They describe two different accounts.

The split exists because an upgrade replaces the code and leaves the address alone. The stub keeps its address and its pointer, and an upgrade rewrites programdata.

All of this depends on the owner. The upgradeable loader is `BPFLoaderUpgradeab1e11111111111111111111111`. A program under a non-upgradeable loader holds its code in the account itself and has no second account to reconcile, so the script checks the owner before it reads anything else. The account command is `solana account`, singular, and everything below applies to it.

## The two layouts

Byte ranges below are start-inclusive and end-exclusive, the convention of `subarray(4, 36)`: 0 to 4 is four bytes, and 4 to 36 is thirty-two.

| Account | Bytes | Field | Content |
|---|---|---|---|
| Program account | 0 to 4 | enum tag | u32 little-endian, value 2 |
| Program account | 4 to 36 | programdata address | 32-byte public key |
| Programdata | 0 to 4 | enum tag | u32 little-endian, value 3 |
| Programdata | 4 to 12 | slot | u64 little-endian, the slot of the last deploy or upgrade |
| Programdata | 12 to 13 | authority flag | 1 when an upgrade authority follows, 0 when there is none |
| Programdata | 13 to 45 | upgrade authority | 32-byte public key, counted only when the flag is 1 |
| Programdata | 45 to end | program bytes | the compiled program plus any room left unused |

The programdata header takes 4 + 8 + 1 + 32 = 45 bytes, and the program bytes start at offset 45. `getAccountInfo` reports the account's full length as `space` even when a `dataSlice` trims the returned bytes. The script uses that: it asks for the first 45 bytes of programdata, enough for the slot and the authority, and takes the length from `space`, so a multi-megabyte program never crosses the wire.

## Reconciling the two outputs

| CLI field | Source on chain | Value |
|---|---|---|
| `solana account` Length | program account `space` | 36 |
| `solana account` Balance | program account `lamports` | the stub's lamports |
| `solana program show` Data Length | programdata `space` minus 45 | size of the program area |
| `solana program show` Balance | programdata `lamports` | programdata's lamports |

The Agave CLI's Data Length leaves out the 45-byte header, so `solana account <programdata address>` reports 45 more than `show` does. The length gap between the two commands is that figure minus 36. Balances need no adjustment: each is the lamports of its own account, and neither command adds the two together. What it costs to hold the program is the sum.

Each balance can be checked against the rent-exempt minimum for its size. The per-byte rate comes from the node through `getMinimumBalanceForRentExemption`, so the script asks it for both sizes. For the 36-byte stub the node answered 833,120 lamports, which is 164 times 5,080. The script prints each answer beside the real balance, and for programdata it also prints the surplus (lamports minus minimum). A surplus above zero means extra lamports were sent to the account, or it was funded under an earlier, higher rent rate. The [rent-exempt minimum calculator](https://carbium.sh/library/howsolana/rent-exempt-minimum-calculator) covers the formula on its own.

## Extra room from `--max-len`

A program deployed with extra room (the `--max-len` option) allocates programdata larger than its first binary, so a later upgrade with a bigger binary fits without a resize. `solana program extend` grows an existing program the same way. In both cases `show` reports the allocated area as Data Length, and the balance covers all of it. Two programs with identical code differ in both figures when only one was deployed with room.

For an assistant the consequence is wording. `space` minus 45 is the capacity of the program area, and a sentence like "the program is 1.2 MB" quotes capacity. The script's output labels it that way.

## The script

One file on @solana/kit 8.6.0, run by Node 24 directly from the TypeScript. Set `CARBIUM_KEY` first; the file exits with a message when it is missing. `CARBIUM_RPC_URL` overrides the endpoint, which defaults to `https://services.carbium.sh`. The argument is a program address; with none, it reads a busy upgradeable program.

`main.ts` (run: `node main.ts`)

```ts
// SI0055 · Program size and balance answers
// https://carbium.sh/library/si/program-size-and-balance-answers
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Reconcile `solana program show` with `solana account` for one upgradeable program. Run: CARBIUM_KEY=... node main.ts [programId]
import { createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder, isAddress } from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));

const LOADER = "BPFLoaderUpgradeab1e11111111111111111111111";
const HEADER = 45n; // programdata: tag 0..4, slot 4..12, flag 12..13, authority 13..45
const sol = (n: bigint) => `${n / 1_000_000_000n}.${String(n % 1_000_000_000n).padStart(9, "0")}`;
const show = (v: unknown) => JSON.stringify(v, (_, x) => (typeof x === "bigint" ? x.toString() : x), 1);
function fail(msg: string): never {
  console.error(msg);
  process.exit(1);
}
function settled<T>(r: PromiseSettledResult<T>, what: string): T | undefined {
  if (r.status === "fulfilled") return r.value;
  console.error(`${what} failed: ${String(r.reason)}`);
  return undefined;
}

const target = process.argv[2] ?? "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
if (!isAddress(target)) fail(`Not a Solana address: ${target}`);

const stub = await rpc
  .getAccountInfo(target, { commitment: "confirmed", encoding: "base64" })
  .send()
  .catch((e) => fail(`getAccountInfo on the program failed: ${String(e)}`));
const account = stub.value;
if (!account) fail(`${target} holds no account at confirmed.`);
if (String(account.owner) !== LOADER) fail(`Owner is ${account.owner}, not the upgradeable loader: no second account to reconcile.`);
const stubBytes = Buffer.from(account.data[0], "base64");
if (stubBytes.length !== 36 || stubBytes.readUInt32LE(0) !== 2) fail("The program account is not a 36-byte stub with tag 2.");
const dataAddress = getAddressDecoder().decode(stubBytes.subarray(4, 36));

const [dataRes, stubMinRes] = await Promise.allSettled([
  rpc.getAccountInfo(dataAddress, { commitment: "confirmed", encoding: "base64", dataSlice: { offset: 0, length: 45 } }).send(),
  rpc.getMinimumBalanceForRentExemption(BigInt(stubBytes.length)).send(),
]);
const data = settled(dataRes, "programdata read");
const stubMin = settled(stubMinRes, "rent minimum for the program account");
const stubLamports = BigInt(account.lamports);
console.log("solana account", target, show({ length: account.space, lamports: stubLamports, sol: sol(stubLamports), slot: stub.context.slot, rentMinimum: stubMin }));

if (!data || !data.value) fail("No programdata account to read: the read failed or the program was closed.");
const pd = data.value;
if (pd.space == null) fail("The node left out `space` for programdata.");
const head = Buffer.from(pd.data[0], "base64");
if (head.length < 45 || head.readUInt32LE(0) !== 3) fail("The programdata header is not tag 3.");
const space = BigInt(pd.space);
const dataLamports = BigInt(pd.lamports);
const authority = head[12] === 1 ? getAddressDecoder().decode(head.subarray(13, 45)) : null;
const [dataMinRes] = await Promise.allSettled([rpc.getMinimumBalanceForRentExemption(space).send()]);
const dataMin = settled(dataMinRes, "rent minimum for programdata");

console.log("solana account", dataAddress, show({
  length: space,
  lamports: dataLamports,
  slot: data.context.slot,
  rentMinimum: dataMin,
  surplus: dataMin === undefined ? undefined : dataLamports - BigInt(dataMin),
}));
console.log("solana program show", show({
  dataLength: space - HEADER,
  meaning: "capacity of the program area, not the compiled program's length",
  balance: dataLamports,
  sol: sol(dataLamports),
  lastDeploySlot: head.readBigUInt64LE(4),
  upgradeAuthority: authority,
}));
console.log("differences", show({
  headerBytes: HEADER,
  lengthGap: space - HEADER - BigInt(account.space),
  balanceGap: dataLamports - stubLamports,
  bothAccounts: stubLamports + dataLamports,
}));
```

The script reads the program account first and stops unless the owner is the upgradeable loader and the data is the 36-byte stub. It then reads the first 45 bytes of programdata and prices the stub's size in the same step. The programdata minimum is requested last, since it needs `space`. Each call is settled on its own, so a failure prints its name and the other output stays. Both account reads name `confirmed`, and each print carries its `context.slot`: the reads happen at different moments, and an upgrade between them would give numbers from two states.

Each `getAccountInfo` is an account read at 10 cells, so the two reads cost 20 cells against a [rate class](https://carbium.sh/docs#limits). The two `getMinimumBalanceForRentExemption` calls carry their own admission charge on top of the 20.

## Where it ends

- `space` minus 45 is allocated room. The length of the compiled program inside it is on neither command's list, and finding it means reading all of programdata and deciding where the program ends. The script reads 45 bytes and makes no claim about code length.
- The arithmetic follows the Agave CLI. Run both commands against the same address and the figures should match the script's account and `program show` lines, up to changes between the reads.
- Only the upgradeable loader is handled. Another owner stops the script with the owner's address. A closed programdata account leaves a stub that points at nothing, and the script says so and exits.
- Balances are one confirmed read each. A busy program's balance can change right after the read, and the printed slot says when the figures held.
- The rent minimum is the amount for that size under today's settings. An account funded under earlier settings, or given extra lamports, shows a surplus, and the script prints it for programdata without explaining why.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The assistant tells the user that one of the two commands is wrong because the lengths and balances differ. | Return the reconciliation table with the answer. Name the account each command reads: the stub for `solana account`, programdata for `solana program show`. |
| The assistant quotes Data Length as the size of the program's code. | Call it the capacity of the program area. A program deployed with extra room or later extended shows more than its code needs, and only a read of the whole account can say where the code ends. |
| The script stops with a message that the owner is not the upgradeable loader. | Report the owner and that account's own length and balance, since there is no second account to add. Call it a single-account program only when the owner is a BPF loader, because the address could also be a wallet or a data account. |
| The programdata read returns null. | The program was closed and the stub points at nothing. Report it as closed and give the stub's balance only. |
| The answer for programdata arrives without `space`. | Read the account again without `dataSlice` and take the decoded data length. The answer is much larger, so do it only for this case. |
| The programdata balance is above its rent minimum. | Report both numbers and the surplus. Extra lamports were sent to the account, or it was funded under an earlier, higher rent rate, and neither command separates the two. |

## Questions

### Which number should an assistant give for what a program costs to hold?

The sum of the stub's balance and programdata's balance. Neither command prints that sum, and the script prints it with the differences.

### Why is the program account always 36 bytes?

It holds a 4-byte tag and a 32-byte programdata address, and nothing else. An upgrade rewrites programdata and leaves the stub as it was.

### Does `solana program show` count the 45-byte header in Data Length?

The Agave CLI leaves it out, so Data Length is the programdata length minus 45. Reading `space` on the programdata address and subtracting 45 reproduces it.

### Where does the same split matter outside the CLI?

Any tool that reads an address and reports its size, owner or balance sees the stub. For a wider read on what an address is, see [Address type explainer](https://carbium.sh/library/si/address-type-explainer).

## Related

- [Rent-exempt minimum calculator](https://carbium.sh/library/howsolana/rent-exempt-minimum-calculator) (How to use Solana, HS0020)
- [Address type explainer](https://carbium.sh/library/si/address-type-explainer) (AI and blockchain, SI0031)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
