---
id: HS0020
title: "Rent-exempt minimum calculator"
url: https://carbium.sh/library/howsolana/rent-exempt-minimum-calculator
collection: How to use Solana
category: Accounts and balances
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Rent-exempt minimum calculator

One TypeScript file takes account sizes in bytes or existing account addresses and prints the rent-exempt minimum in lamports and SOL. It checks each answer against the local formula and shows whether an existing account holds enough.

## What the minimum is

Every Solana account has to hold a minimum number of lamports to exist. The amount depends on one input, the length of the account's data in bytes. It does not depend on what the data holds or who owns the account. An account at or above the minimum is rent exempt and stays on chain until its owner closes it. A transaction that would leave an account with a balance above zero but under the minimum fails, and so does one that creates an account with too little.

The rule is plain arithmetic. The cluster currently asks 5,080 lamports for each byte of data plus 128 bytes of overhead for the account's metadata, so the minimum for a data length n is (128 + n) x 5,080. An account with no data needs 650,240 lamports, which is 0.00065024 SOL.

You could hard code that formula, and the file below computes it as a cross-check. The cluster owns the rate, though. `getMinimumBalanceForRentExemption` returns the number the cluster applies right now, so call it whenever the amount decides whether a transaction lands.

Two jobs use the call. Before you create an account, such as a mint, a token account or a data account for your own program, you fund it with at least the minimum for its size. Before you move SOL out of an account that already exists, you work out how much has to stay behind.

## The code

Install `@solana/kit` at 8.6.0, export `CARBIUM_KEY` and run the file with Node 24. Each argument is either a data size in bytes or the address of an account that exists. With no arguments the file prints three common sizes: a system account, a token account and a mint.

`main.ts` (run: `node main.ts [size-in-bytes-or-account-address ...]`)

```ts
// HS0020 · Rent-exempt minimum calculator
// https://carbium.sh/library/howsolana/rent-exempt-minimum-calculator
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

import {
  address,
  createDefaultRpcTransport,
  createSolanaRpcFromTransport,
} 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 } }),
);

// Local cross-check: (128 bytes of account overhead + data) x 5,080 lamports.
const formula = (size: number): bigint => BigInt(128 + size) * 5080n;
const sol = (l: bigint): string =>
  `${l / 1_000_000_000n}.${(l % 1_000_000_000n).toString().padStart(9, "0")}`;

// An argument is a data size in bytes or the address of an existing account.
async function check(arg: string): Promise<string> {
  let size = Number(arg);
  let held: bigint | undefined;
  if (!/^\d+$/.test(arg)) {
    const { value } = await rpc
      .getAccountInfo(address(arg), {
        encoding: "base64",
        dataSlice: { offset: 0, length: 0 },
      })
      .send();
    if (!value) throw new Error(`no account at ${arg}`);
    size = Number(value.space);
    held = value.lamports;
  }
  const min = await rpc.getMinimumBalanceForRentExemption(BigInt(size)).send();
  let line = `${size} bytes: ${min} lamports (${sol(min)} SOL)`;
  line += min === formula(size) ? ", matches formula" : `, formula says ${formula(size)}`;
  if (held !== undefined) {
    line += held >= min
      ? `; ${arg} holds ${held}, rent exempt`
      : `; ${arg} holds ${held}, short by ${min - held}`;
  }
  return line;
}

const args = process.argv.slice(2);
const targets = args.length ? args : ["0", "165", "82"];
const results = await Promise.allSettled(targets.map((t) => check(t)));
let ok = 0;
results.forEach((r, i) => {
  if (r.status === "fulfilled") {
    ok++;
    console.log(r.value);
  } else {
    console.error(`${targets[i]}: ${r.reason instanceof Error ? r.reason.message : r.reason}`);
  }
});
if (!ok) process.exit(1);
```

A size goes straight to `getMinimumBalanceForRentExemption`. An address first goes through `getAccountInfo`, whose reply carries the account's `space`, its data length in bytes. The file asks for a zero-length slice of the data, so no account data comes back, and reads the size from `space`. It then asks for the minimum at that length and compares the account's lamports with it. The call leaves commitment out, so `@solana/kit` 8.6.0 fills in `confirmed` for the account read.

Lamports stay `bigint` from the reply to the last line, and the SOL text is built with integer division, so no float touches the amount. Every argument runs under `Promise.allSettled`. A mistyped address prints its own error on stderr and leaves the other lines intact, and the process exits with code 1 only when every argument failed.

## Reading the output

A line has four parts: the data size, the minimum from the cluster in lamports and SOL, whether it matches the local formula, and, for an address, what the account holds against that minimum. An account that sits under its minimum prints how many lamports it is short.

| Account | Data bytes | Minimum lamports at 5,080 per byte | SOL |
|---|---|---|---|
| System account | 0 | 650,240 | 0.00065024 |
| Nonce account | 80 | 1,056,640 | 0.00105664 |
| Token mint | 82 | 1,066,800 | 0.0010668 |
| Token account | 165 | 1,488,440 | 0.00148844 |
| Multisig account | 355 | 2,453,640 | 0.00245364 |

The 165 bytes of a token account explain why opening one costs about 0.0015 SOL, and why ten token accounts lock up about 0.015 SOL in rent. Whoever created each account paid that rent, often the sender, because the receiving wallet does not always fund them. The money is a deposit. Closing the account sends its lamports to an address you name, and the minimum comes back.

> The minimum is a floor on the whole account balance. A transfer of a fee payer's SOL has to leave the fee payer at or above its own minimum after the transaction fee is taken, or at exactly zero, so keep the fee on top of the figure this file prints.

## On Carbium

The size lookup is a single JSON-RPC method on the [endpoint](https://carbium.sh/docs#endpoints) at `https://services.carbium.sh`, and the file sends it through the same transport as the account read. `getAccountInfo` is an account read at 10 cells, and [account reads](https://carbium.sh/docs#rpc) run at 0.5 per second on Free, 15 on Dev, 50 on Business and 400 on Pro. The file sends every argument at once, which suits a handful; on a Free key, pace a loop over many addresses.

To price many sizes in one round trip, post a JSON array of up to 100 `getMinimumBalanceForRentExemption` calls with a raw `fetch`, since `@solana/kit` has no batch call. A table of sizes you need often is small enough to read once at start up and keep in memory.

For the SOL held by a whole list of wallets, read [SOL balances for many accounts](https://carbium.sh/library/howsolana/sol-balances-for-many-accounts), which covers `getMultipleAccounts` and its per-call limits. For a first project that stays read-only, [Read-only hackathon starter](https://carbium.sh/library/blockchainideas/read-only-hackathon-starter) shows a wider set of reads on one key.

## Keeping an account funded

Resizing changes the minimum. If a program grows an account's data, the extra bytes cost 5,080 lamports each, and the account needs that top-up in the same transaction. Compute the top-up at run time: ask `getMinimumBalanceForRentExemption` on the client for the new size, or read the Rent sysvar inside the program, and transfer the difference between that figure and the lamports the account holds.

For an account you only read, the check is a health test. Pass its address and compare the lamports it holds with the minimum for its current data length. The file prints the held figure, so an account funded at the older, higher rate, or any account that holds more than its minimum, shows a held figure above the minimum. Only whoever controls the account's lamports can move that surplus out: the signer for a system account, the owner program for a program account such as a token account.

## Where it ends

The file measures an account as it is today. It cannot tell you the size a future account will have. For a Token-2022 mint or token account with extensions, the data length is larger than 82 or 165 and depends on which extensions the account carries, so pass the real size from the program's documentation or from an existing account of the same kind. Funding a new Token-2022 account with the classic 165-byte figure leaves it short.

The result covers rent exemption only. It does not include the transaction fee, a priority fee, or the minimums of other accounts the same transaction creates. A swap or a mint that opens three accounts needs three minimums plus fees.

The local formula is a cross-check and goes stale if the cluster changes its rent rate. The call keeps answering correctly, and the file prints the formula's figure beside it when the two differ. An address that does not exist at confirmed commitment has no data length, so the file reports it as missing.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| A transaction fails with InsufficientFundsForRent, or the error says an account has insufficient funds for rent. | Some account in the transaction ends below its minimum. Run the file with that account's real data size and fund it with at least the printed amount, plus the fee on the fee payer. |
| A token account created with 1,488,440 lamports still fails for a Token-2022 mint. | The account carries extensions and its data is longer than 165 bytes. Read the size of an existing account of the same kind or take it from the extension list, then ask for the minimum at that length. |
| The file prints `no account at <address>`. | The address does not exist at confirmed commitment. Check the spelling and the network, and for an account you just created wait until its transaction is confirmed before you read it. |
| The file prints an invalid address error for one argument. | Anything that is not all digits is read as an address. Pass sizes as plain integers and addresses as full base58 text. |
| The printed minimum differs from the formula line in your own code. | Trust the RPC figure. Your hard-coded rate is out of date or you left out the 128 bytes of overhead, which the RPC adds for you when you pass only the data length. |

## Questions

### Do I get the rent back when I close an account?

Yes. Closing an account sends all of its lamports, rent deposit included, to the address you choose. Only the transaction fee is spent.

### Does the minimum grow over time?

No. It is fixed by the data length and the cluster's rent rate, and an account that holds the minimum is exempt for as long as it exists. The figure moves only if the cluster changes the rate.

### Should I pass the data length or the length plus 128?

Pass the data length alone. The 128 bytes of metadata overhead are added by the call, as the 0-byte row of 650,240 lamports shows.

### Can I cache the answer?

Yes, per size. A cached figure suits display and estimates, since the rate changes only when the cluster changes it. Ask again before funding an account.

### Do I need a private key to run this?

No. Both calls only read. The Carbium key identifies your account and nothing is signed or sent.

## Related

- [SOL balances for many accounts](https://carbium.sh/library/howsolana/sol-balances-for-many-accounts) (How to use Solana, HS0016)
- [Read-only hackathon starter](https://carbium.sh/library/blockchainideas/read-only-hackathon-starter) (Blockchain ideas, BI0012)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
