If you are paid a salary in India and pay rent, part of your House Rent Allowance (HRA) can be tax-free under the old tax regime. The rule fits in one sentence, which makes it look like a one-liner. We built it for Finance Planner Online, a free tax planner for India, and it turned into three small design decisions. Here they are, with the code.

1. The rule is a minimum of three limits

The tax-free part of HRA is the least of:

  • the HRA you actually received,
  • the rent you paid minus 10% of your basic salary,
  • 50% of basic if the rented home is in a listed city, 40% elsewhere.
/** Section 10(13A): least of HRA received, rent − 10% of basic, and 50/40% of basic. */ export function hraExemption( input: Pick<TaxInput, "hraReceived" | "rentPaid" | "basicSalary" | "cityClass" | "fyStartYear">, ): number { const { hraReceived, rentPaid, basicSalary, cityClass } = input; if (hraReceived <= 0 || rentPaid <= 0 || basicSalary <= 0) return 0; const r = rulesFor(yearOf(input)); const byRent = rentPaid - r.hraRentThresholdOfBasic * basicSalary; const byBasic = r.hraBasicShare[cityClass] * basicSalary; return clamp0(Math.min(hraReceived, byRent, byBasic)); } 

Two details matter. The percentages come from a rule set for the year, not from constants in the function. And clamp0 is there because rent below 10% of basic makes the second limit negative; the exemption is then zero, not a negative number that quietly raises someone's income.

2. The city list depends on the year

For decades the 50% limit covered four cities: Delhi, Mumbai, Kolkata and Chennai. From FY 2026-27, Rule 279 of the Income-tax Rules, 2026 adds Bengaluru, Hyderabad, Pune and Ahmedabad. So "is Bengaluru a metro?" has no answer until you know which year you are computing.

We store when each city joined rather than a boolean:

export const HRA_CITIES_ALL: HraCity[] = [ { id: "delhi", label: "Delhi", metroFromFY: 0 }, { id: "mumbai", label: "Mumbai", metroFromFY: 0 }, { id: "kolkata", label: "Kolkata", metroFromFY: 0 }, { id: "chennai", label: "Chennai", metroFromFY: 0 }, { id: "bengaluru", label: "Bengaluru", metroFromFY: 2026 }, { id: "hyderabad", label: "Hyderabad", metroFromFY: 2026 }, { id: "pune", label: "Pune", metroFromFY: 2026 }, { id: "ahmedabad", label: "Ahmedabad", metroFromFY: 2026 }, { id: "other", label: "Anywhere else", metroFromFY: null }, ]; export function isHraMetro(cityId: string, fyStartYear: number): boolean { const city = rulesFor(fyStartYear).hraCities.find((c) => c.id === cityId); if (!city || city.metroFromFY === null) return false; return fyStartYear >= city.metroFromFY; } 

The difference is real money. A Bengaluru renter with a basic of ₹50,000 a month, HRA of ₹25,000 and rent of ₹30,000 gets all ₹3,00,000 of the year's HRA tax-free in FY 2026-27. Under the FY 2025-26 rules only ₹2,40,000 was, and ₹60,000 was taxed as salary. Same person, same flat, one year apart. A test pins both answers, so a refactor can't move a city by accident.

3. You can't annualise when the salary changes mid-year

The tempting shortcut is to add up the year's basic, HRA and rent and apply the rule once. The rule actually works period by period: when basic, rent or the city changes, each stretch gets its own three limits, scaled by its share of the year, and the results are summed.

for (const p of periods) { const share = clamp0(p.months) / 12; const byHraReceived = clamp0(p.hraReceived) * share; const byRent = (clamp0(p.rentPaid) - threshold * clamp0(p.basicSalary)) * share; const byBasic = p.basicShare * clamp0(p.basicSalary) * share; const periodExempt = p.hraReceived <= 0 || p.rentPaid <= 0 || p.basicSalary <= 0 ? 0 : clamp0(Math.min(byHraReceived, byRent, byBasic)); exempt += periodExempt; } 

Example (FY 2026-27, Bengaluru, rent ₹25,000 a month all year): basic is ₹40,000 a month for six months, then ₹60,000 after a raise, with HRA at half of basic.

  • First half: the 50%-of-basic limit binds, ₹1,20,000.
  • Second half: the rent limit binds, ₹1,14,000.
  • Period by period: ₹2,34,000 tax-free.
  • The annual shortcut says ₹2,40,000, because it lets the first half's spare rent cover the second half.

Different limits bind in different stretches, so the shortcut overstates the exemption. Our test for this asserts only that the two answers differ when different limits bind, so nobody can swap the shortcut back in unnoticed.

What I'd tell anyone writing tax code

Keep rates and lists in a rule set per year, keep the arithmetic in small pure functions, and write the test from a worked example a person can check by hand.

The calculator these functions drive is free and needs no sign-in. It shows the three limits and marks the one that decides your figure: https://financeplanneronline.com/hra-calculator?utm_source=devto&utm_medium=article&utm_campaign=arlen-marketing

Disclosure: our company, TwentyFox, makes Finance Planner Online. This article was written by an AI agent working for us and checked against the code and the live page. HRA exemption applies only in the old regime. FY 2026-27 figures are provisional until the year's rules are confirmed; not tax advice.