Technical writing

CBP US Trade Statistics: The Federal Dataset Behind Every Import and Export

· 13 min read· AI Analytics
Federal DataCBPTradeEconomics

Every container that clears US Customs, every shipment that crosses at Laredo or Long Beach or JFK, generates a transaction record. US Customs and Border Protection, working alongside the Census Bureau's Foreign Trade Division, assembles those records into the most comprehensive trade dataset in the world: monthly import and export statistics by commodity, country, and port of entry, going back to 1989. The headline trade deficit number that moves currency markets every month is derived from this dataset. So are the tariff revenue figures, the supply chain concentration maps, and the sanctions evasion investigations.

Despite its importance, the underlying dataset is less understood than the headline numbers it generates. Most coverage focuses on the monthly FT-900 trade report — the “trade deficit” figure — without engaging with the structure of the data beneath it. This article covers what the data contains, how it is collected, where to access it, how to read HTS commodity codes, what the current trade flows reveal, and how to analyze it programmatically.

How the data is collected

Trade statistics originate from two legal reporting systems that feed into a single analytical output. Importers file entry documents with CBP for every shipment entering the United States. Exporters file Electronic Export Information (EEI) through the Automated Export System (AES) for shipments above certain value thresholds — generally $2,500 or when an export license is required. Both pipelines flow into the Census Bureau's Foreign Trade Division, which compiles them into the monthly statistical releases.

CBP collects customs entry data as part of its border enforcement and tariff assessment function. When a shipment clears customs, the importer of record (or their customs broker) files an entry that specifies the commodity using a 10-digit Harmonized Tariff Schedule (HTS) code, the country of origin, the customs district and port of entry, the quantity, and the import value. That import value is reported on a cost, insurance, and freight (CIF) basis — the total landed cost to the US port of entry — for the purposes of the CBP entry record, but the Census Bureau converts it to a customs value (essentially the foreign market price, excluding freight and insurance) for statistical publication. Export values are reported on a free on board (FOB) basis, meaning the value at the US export port before international freight and insurance are added.

The CIF/FOB asymmetry matters for trade balance interpretation. The “trade deficit” as reported in the FT-900 compares customs-value imports (which exclude international freight and insurance) to FOB exports. Because imports include transportation costs in the goods total when international freight is paid to foreign carriers, some economists argue that trade balance figures understate the true bilateral balance in services flowing in the opposite direction.

The data structure

Each record in the published trade statistics represents a unique combination of the following dimensions:

Dimensions in CBP/Census trade data:
  commodity      — HTS code (imports) or Schedule B code (exports), 10 digits
  partner        — Country of origin (imports) or destination (exports)
                   identified by Census country code and ISO-3166 alpha-2
  district/port  — Customs district (2-digit) and port of entry (4-digit)
                   CBP maintains ~330 ports of entry and ~45 districts
  time           — Year and month (YYYY-MM)

Measures:
  value          — Customs value in USD (imports) or FOB value in USD (exports)
  quantity_1     — Primary unit (kg, liters, barrels, units — HTS-defined)
  quantity_2     — Secondary unit where applicable (some HTS codes track two)
  statistical_month — Month the transaction was recorded (vs. entry date)

Commodity codes are the most important dimension for analytical work. Imports use the Harmonized Tariff Schedule of the United States (HTS), which is the US implementation of the international Harmonized System. Exports use the Schedule B classification, which is maintained by the Census Bureau and mirrors the HS at the 6-digit international level but diverges at the 7–10 digit level. For cross-border comparisons and international benchmarking, both systems aggregate to the 6-digit HS level, which is standardized across all countries that have adopted the Harmonized System (virtually all major trading nations).

Decoding HTS codes

The Harmonized Tariff Schedule is a hierarchical classification system that assigns every traded good a 10-digit code. Reading these codes requires understanding the hierarchy:

HTS code: 8471.30.0100

  84        — Chapter: Nuclear reactors, boilers, machinery and mechanical appliances
  8471      — Heading: Automatic data-processing machines and units thereof
  8471.30   — Subheading (HS-6): Portable digital ADP machines (laptops)
  8471.30.01 — US-8 (US-level breakout): Weighing not more than 10 kg
  8471.30.0100 — US-10 (statistical suffix): Full 10-digit for tariff/quota purposes

Structure:
  Chapters 1–97: main classification chapters
  Chapter 98: special provisions (returning goods, re-imports)
  Chapter 99: temporary provisions (tariff-rate quotas, Section 301/232 additions)

Chapter groups (abbreviated):
  01–05  Live animals and animal products
  06–14  Vegetable products
  16–24  Prepared foodstuffs, beverages
  25–27  Mineral products (includes petroleum: Ch. 27)
  28–38  Chemicals
  39–40  Plastics and rubber
  44–49  Wood, paper, printed matter
  50–63  Textiles and apparel
  64–67  Footwear, headgear
  72–83  Base metals
  84–85  Machinery, electronics (the largest import chapters by value)
  86–89  Vehicles, aircraft, vessels
  90–92  Precision instruments, optical
  93     Arms and ammunition

The authoritative reference for decoding any HTS code is the USITC HTS database at hts.usitc.gov. It publishes the complete annotated tariff schedule with general rates of duty, special rates (for FTA partners), and additional rates (for Section 301 and Section 232 tariff actions). The HTS is revised annually, with some chapters more heavily modified than others as trade agreements and tariff actions come into effect.

For export classification, the Census Bureau maintains the Schedule B search tool at scheduleB.census.gov, which allows keyword and description search to find the correct 10-digit Schedule B number. The first 6 digits of Schedule B match the HS and the first 6 digits of HTS for the same commodity class, enabling import/export cross-tabulation at the HS-6 level.

CBP entry statistics vs. the FT-900 trade report

The monthly FT-900 report — formally titled U.S. International Trade in Goods and Services and published jointly by the Census Bureau and the Bureau of Economic Analysis — is the source of the headline trade deficit figure. It is derived from CBP entry and AES export data but is not identical to it. Understanding the relationship requires separating three concepts.

CBP entry data is the raw transactional record: every customs entry filed, with its HTS code, country, value, and port. This data is maintained by CBP for tariff collection and border enforcement purposes. The Census Bureau accesses it under a data-sharing agreement to compile trade statistics.

Census trade statistics (published monthly at census.gov/foreign-trade and accessible via USA Trade Online) are compiled from CBP entry and AES export data after applying methodological adjustments: certain low-value shipments are excluded (imports below $800 are exempt from formal entry), non-market transactions are classified separately, and estimates are made for the gap between the reference month and the data availability lag. These are the detailed, commodity-level statistics that support the breakdown by HTS chapter, country, and port.

The FT-900 takes the Census trade statistics and adds BEA's estimates for services trade (financial services, travel, royalties, transportation) to produce the combined goods-and-services trade balance that feeds into GDP calculations. The goods-only deficit from Census is always larger (more negative) than the combined deficit because the United States runs a persistent surplus in services. The services estimates are not derived from CBP data — they come from BEA surveys and financial account data — and are not disaggregated by commodity or country at the same granularity as goods.

The monthly trade deficit feeds directly into the GDP calculation. Net exports (exports minus imports of goods and services) is one of the four expenditure components of GDP: GDP = C + I + G + (X−M). A wider trade deficit reduces GDP in the quarter it occurs, all else equal. This is why trade data releases routinely move bond and equity markets, and why GDP advance estimates issued before full trade data is available sometimes carry large revision risk from the trade component.

Access channels

USA Trade Online

The primary public interface for US trade statistics is USA Trade Online at usatrade.census.gov. It provides a browser-based query interface for building custom data extracts: select commodity codes (by chapter, heading, or specific 10-digit HTS), select countries (by individual country or region group), select date range (monthly, annual), and choose the trade flow direction (imports, exports, or balance). Results can be downloaded as CSV or Excel. USA Trade Online covers imports back to 1989 and exports back to 1989 for most country-commodity combinations.

USA Trade Online requires free registration but has no programmatic API. For automated or bulk access, the Census Bureau's data API is the appropriate channel.

Census Foreign Trade API

The Census Bureau exposes trade time-series data through its standard data API at api.census.gov. The relevant endpoints are:

# Imports by HTS and country
https://api.census.gov/data/timeseries/intltrade/imports/hs
  ?get=GEN_VAL_MO,CTY_CODE,CTY_NAME,I_COMMODITY,I_COMMODITY_LDESC,time
  &CTY_CODE=5700             # China country code
  &COMM_LVL=HS2              # 2-digit chapter aggregation
  &time=2024-01
  &key=YOUR_KEY

# Exports by Schedule B and country
https://api.census.gov/data/timeseries/intltrade/exports/schb
  ?get=ALL_VAL_MO,CTY_CODE,CTY_NAME,E_COMMODITY,E_COMMODITY_LDESC,time
  &CTY_CODE=5700
  &COMM_LVL=HS2
  &time=2024-01
  &key=YOUR_KEY

# Country codes: 5700=China, 2010=Canada, 2050=Mexico, 5520=Vietnam
# COMM_LVL options: HS2, HS4, HS6, HS10 (increasing granularity)
# GEN_VAL_MO: general imports value; CON_VAL_MO: consumption imports value

The API key is free from api.census.gov/data/key_signup.html. Without a key, the API allows 500 requests per day, sufficient for ad-hoc queries. With a key, the rate limit is significantly higher. The full list of supported country codes and commodity aggregation levels is documented in the API variable definitions at api.census.gov/data/timeseries/intltrade/imports/hs/variables.json.

FRED integration

The Federal Reserve Bank of St. Louis's FRED database integrates the aggregate trade deficit figures from the FT-900 as named series: BOPGSTB(goods and services trade balance), BOPGSTBGS, and individual import and export component series. FRED is the easiest access point for the headline monthly balance time series and for plotting trade flows against macroeconomic variables (exchange rates, industrial production, GDP growth). FRED does not carry the commodity-level or country-level detail — for that, the Census API or USA Trade Online is required.

Bulk downloads

The Census Bureau publishes monthly bulk data files at census.gov/foreign-trade/data/index.html. These include state export data (exports by originating state, HTS chapter, and destination country), port-level data (imports and exports by US port of entry and exit), and the full HS-10 monthly detail files. The bulk files are the appropriate source for pipelines that require port-level or full 10-digit commodity resolution, as the API supports only up to HS-6 aggregation for most queries.

Top US trading partners

The three largest US trading partners by total goods trade (imports plus exports combined) in 2024 were Canada, Mexico, and China, collectively accounting for roughly 43 percent of total US goods trade. The ranking has been stable for more than a decade, though the bilateral composition has shifted substantially under Section 301 tariff pressure.

Top US trading partners by 2024 goods trade (approximate):
  Canada          ~$780B total (imports: ~$440B, exports: ~$340B)
  Mexico          ~$810B total (imports: ~$505B, exports: ~$325B)
  China           ~$580B total (imports: ~$440B, exports: ~$145B)
  Germany         ~$220B total
  Japan           ~$210B total
  South Korea     ~$185B total
  Vietnam         ~$145B total (imports surging post-301)
  Taiwan          ~$145B total (semiconductors driving exports)
  United Kingdom  ~$140B total
  India           ~$130B total

Leading US import commodity categories (2024):
  Ch. 84-85  Machinery, electrical equipment, electronics: ~$900B
  Ch. 87     Vehicles and parts:                           ~$330B
  Ch. 27     Mineral fuels (crude oil, refined products):  ~$200B
  Ch. 30     Pharmaceuticals:                              ~$190B
  Ch. 71     Precious stones, jewelry:                     ~$110B

Leading US export commodity categories (2024):
  Ch. 84-85  Machinery and electronics:                    ~$320B
  Ch. 88     Aircraft and spacecraft:                      ~$115B
  Ch. 27     Petroleum products and LNG:                   ~$280B
  Ch. 30     Pharmaceuticals:                              ~$110B
  Ch. 12     Oilseeds (soybeans):                         ~$55B

The United States runs bilateral trade deficits with China, Mexico, Vietnam, Germany, Japan, and Ireland (the last primarily due to pharmaceutical transfer pricing). It runs surpluses with Canada (energy trade drives this), the Netherlands, Australia, and the United Kingdom. The bilateral deficit with Mexico surpassed China in 2023 for the first time in decades, a direct consequence of trade diversion under Section 301 tariffs.

Section 301 tariffs and trade diversion

Section 301 of the Trade Act of 1974 authorizes the President to impose tariffs in response to unfair trade practices. Beginning in 2018, the Office of the United States Trade Representative imposed four tranches of Section 301 tariffs on Chinese goods, covering roughly $370 billion in annual imports at rates of 7.5, 25, or 25 percent depending on the product list (Lists 1, 2, 3, and 4A/4B). These tariffs appear in CBP entry data through Chapter 99 HTS codes overlaid on the base commodity classification.

The trade data documents the downstream effects clearly. US imports from China in the affected categories fell significantly after 2018, but total US imports of those commodities did not fall by a corresponding amount. Instead, imports of the same goods rerouted through third countries, a phenomenon economists call trade diversion.

Vietnam is the most documented diversion destination for electronics and machinery. US imports from Vietnam in HS chapters 84–85 (electronics, machinery) more than tripled between 2017 and 2024, while Chinese exports in the same chapters to Vietnam rose sharply during the same period. The pattern is consistent with Chinese manufacturers establishing Vietnamese assembly operations to obtain Vietnamese certificates of origin, sidestepping the Section 301 duties. CBP has issued country of origin enforcement actions in several cases where Vietnamese “transformation” was found to be minimal. The trade data alone does not prove diversion — it is circumstantial — but it provides the numerical baseline for enforcement investigations.

Mexico showed a similar pattern for furniture, steel products, and some electronics categories. The USMCA (United States-Mexico-Canada Agreement) rules of origin require substantial transformation within North America for preferential tariff treatment, but enforcement of those rules at CBP depends on importer declarations and targeted audits rather than transaction-by-transaction verification.

Python: downloading and analyzing trade flows by HTS chapter and country

The following snippet downloads 12 months of US import data from the Census API for China and Vietnam at the 2-digit HTS chapter level, aggregates annual totals, and computes the Vietnam share of bilateral trade as a trade diversion signal. No f-strings or template literals are used to keep the code embeddable.

import requests
import pandas as pd
import io

# Census Foreign Trade API: monthly trade by HTS-2 chapter and partner country
# Endpoint: api.census.gov/data/timeseries/intltrade/imports/hs
# Docs: census.gov/foreign-trade/reference/guides/index.html

BASE = "https://api.census.gov/data/timeseries/intltrade/imports/hs"
API_KEY = "YOUR_CENSUS_API_KEY"

# Pull 12 months of US imports from China, by 2-digit HS chapter
params = {
    "get": "GEN_VAL_MO,CTY_CODE,CTY_NAME,I_COMMODITY,I_COMMODITY_LDESC,time",
    "CTY_CODE": "5700",       # China
    "COMM_LVL": "HS2",        # 2-digit chapter aggregation
    "time": "from+2024-01+to+2024-12",
    "key": API_KEY,
}

resp = requests.get(BASE, params=params)
resp.raise_for_status()

rows = resp.json()
cols = rows[0]
data = pd.DataFrame(rows[1:], columns=cols)
data["GEN_VAL_MO"] = pd.to_numeric(data["GEN_VAL_MO"])
data["month"] = pd.to_datetime(data["time"])

# Aggregate annual imports from China by HS chapter
annual = (
    data
    .groupby(["I_COMMODITY", "I_COMMODITY_LDESC"])["GEN_VAL_MO"]
    .sum()
    .reset_index()
    .rename(columns={"GEN_VAL_MO": "annual_import_usd"})
    .sort_values("annual_import_usd", ascending=False)
)

print("Top 10 import chapters from China (2024):")
print(annual.head(10).to_string(index=False))

# Compare: same chapters from Vietnam (trade-diversion signal)
params_vn = dict(params)
params_vn["CTY_CODE"] = "5520"  # Vietnam

resp_vn = requests.get(BASE, params=params_vn)
data_vn = pd.DataFrame(resp_vn.json()[1:], columns=resp_vn.json()[0])
data_vn["GEN_VAL_MO"] = pd.to_numeric(data_vn["GEN_VAL_MO"])

annual_vn = (
    data_vn
    .groupby(["I_COMMODITY", "I_COMMODITY_LDESC"])["GEN_VAL_MO"]
    .sum()
    .reset_index()
    .rename(columns={"GEN_VAL_MO": "annual_import_usd_vn"})
)

# Side-by-side: chapters where Vietnam share rose as China share fell
comparison = annual.merge(annual_vn, on=["I_COMMODITY", "I_COMMODITY_LDESC"], how="outer").fillna(0)
comparison["vn_share_ratio"] = comparison["annual_import_usd_vn"] / (
    comparison["annual_import_usd"] + comparison["annual_import_usd_vn"] + 1
)
print("\nChapters with highest Vietnam share (diversion candidates):")
print(comparison.sort_values("vn_share_ratio", ascending=False).head(10).to_string(index=False))

For port-level analysis or 10-digit HTS resolution, the bulk monthly files from census.gov/foreign-trade/data/index.html are more appropriate than the API. They are published as fixed-width or CSV files and can be ingested directly into DuckDB for fast analytical queries without loading the full file into memory.

How investigative journalists use trade data

Trade statistics are a primary source for three categories of investigative work: sanctions evasion, counterfeit goods tracking, and supply chain concentration risk. Each exploits a different feature of the publicly available data.

Sanctions evasion detection

The Office of Foreign Assets Control (OFAC) maintains a list of sanctioned countries, entities, and individuals. Trade statistics provide a population-level view of imports from jurisdictions that should have near-zero trade with the United States. Persistent import flows from heavily sanctioned countries — North Korea, Iran, Cuba — at values above de minimis levels are anomalies worth investigating, though country-of-origin misrepresentation (filing a third country as origin when the goods originate in a sanctioned country) means that official trade data may understate the true flows.

The more analytically tractable signal is third-country surge: when US imports from a country that borders or trades heavily with a sanctioned nation spike in exactly the commodity categories the sanctioned nation is known to produce, the pattern suggests transshipment. Commodity flows of sanctioned-country oil exports from Russia through Turkey, India, and the UAE during 2022–2024 generated exactly this pattern in international trade data, visible in the Census import statistics for petroleum products (Chapter 27) from those intermediary countries.

Counterfeit goods

CBP publishes an annual Intellectual Property Rights Seizure Statistics report documenting the value and origin of counterfeit goods seized at the border. The report identifies the top originating countries (China and Hong Kong consistently account for 70–90 percent of seizure value), the product categories most affected (watches, handbags, electronics accessories, pharmaceuticals), and the ports of entry where seizures are concentrated. Cross-referencing the seizure report against the full import statistics for the same commodity chapters from the same originating countries provides context for the seizure rate — what fraction of total declared imports in those categories is intercepted.

Supply chain concentration

The COVID-19 pandemic made supply chain concentration a mainstream policy concern after import statistics revealed that the United States sourced 80–90 percent of certain pharmaceutical active ingredients and personal protective equipment from China. Trade data at the HS-6 or HS-10 level reveals concentration by calculating what share of total US imports in a given commodity category come from the top one or two originating countries.

For semiconductors (HTS 8542: electronic integrated circuits), Taiwan accounts for the majority of advanced logic chip imports while South Korea and Japan supply memory. For rare earth elements (HTS 2846: compounds of rare-earth metals), China accounts for the overwhelming majority of imports. These concentration figures — derived directly from the public trade data — drive policy decisions in the CHIPS Act, the Inflation Reduction Act supply chain provisions, and the national security reviews conducted by the Bureau of Industry and Security.

Trade data does not reveal the importer of record at the company level — that information is in the CBP entry records, which are not fully public. The publicly available data is aggregated to the country-commodity-port-month level, which is sufficient for concentration analysis but not for identifying specific corporate dependencies. For company-level import data, journalists use import manifest data published by Panjiva (a S&P Global product), ImportGenius, and similar commercial aggregators that parse the customs manifest records that are publicly available under FOIA.

Limitations and methodological notes

Several features of the trade statistics require care in interpretation.

De minimis exemptions. Shipments valued below $800 are exempt from formal customs entry under Section 321 of the Tariff Act. These low-value imports — which include a large and growing share of direct-to-consumer e-commerce shipments — are not fully captured in the trade statistics. The Census Bureau estimates their value and includes an aggregate estimate, but the commodity and country detail for de minimis shipments is limited. This creates a known undercount of low-value apparel, electronics accessories, and goods shipped directly from Chinese merchants through platforms like Temu and Shein.

Country of origin vs. country of shipment.Trade statistics report country of origin, not country of last shipment. A laptop assembled in China but shipped to the US via a Vietnamese distribution center should be reported as Chinese origin. In practice, importers may declare the country of last shipment when they lack documentation for origin, and CBP enforcement of origin rules is concentrated on high-risk shipments rather than universal. This creates systematic noise in the country-of-origin data for goods that frequently move through entrepot hubs like Singapore, Hong Kong, and the UAE.

Revision schedule. Monthly trade figures are released approximately five weeks after the reference month. They are revised when late entries are processed: typically the first revision occurs in the following month's release, and further revisions are less common but do occur. Annual revisions are published each year and may materially change monthly figures for the prior year. Time series analysis should use the revised figures from the annual release rather than the initial monthly estimates.

Related writing

The price index behind every inflation headline: BLS CPI-U methodology and data access — How the Bureau of Labor Statistics constructs the Consumer Price Index, what the underlying data contains, and how tariff cost pass-through appears in the commodity-level CPI components.

The demographic backbone: using Census ACS data to contextualize every other federal dataset — The Census Bureau's American Community Survey provides the population denominators that make trade-adjacent regional economic analysis meaningful.

Who owns what: indexing SEC Form 13F institutional holdings data — How institutional investors track trade-exposed equities using the same commodity and country signals visible in the CBP trade statistics.