---
title: Constant-weight codes: error-correcting codewords with the same number of ones — Ground Truth
url: https://groundtruth.day/learn/constant-weight-codes.html
description: A constant-weight code is a set of equal-length bit strings that all contain the same number of ones and stay far enough apart to distinguish errors.
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://groundtruth.day/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

Learn · Beginner

# Constant-weight codes: error-correcting codewords with the same number of ones

A constant-weight code is a collection of equal-length bit strings in which every string contains the same number of 1s, while every pair differs in many bit positions. The fixed number of active positions can fit systems with a limited number of available slots, and the separation between codewords lets a receiver detect or correct errors. Finding a large example proves that at least that many codewords are possible; it does not prove the example is the largest possible.

Imagine a panel with 32 switches, exactly 15 of which must be on. A valid codeword is one allowed switch pattern. If the receiver reads a few switches incorrectly, it can compare the noisy pattern to the allowed patterns and select the closest one. The design goal is to choose patterns far enough apart that small errors do not make two valid messages look alike. Constant-weight codes are useful whenever every message must use the same number of active positions, including certain communication, storage, and experimental-design problems.

## Three numbers describe the problem

A common notation is A(n,d,w). Here, n is the number of bit positions, d is the minimum Hamming distance between any two codewords, and w is the required weight, or number of 1s. For example, A(32,12,15) asks for the largest possible set of 32-bit strings with exactly 15 ones, where every pair differs in at least 12 positions.

Hamming distance is a count: compare two strings position by position and add one for each position that differs. If the minimum distance is d, a code can detect up to d−1 bit errors. It can correct up to floor((d−1)/2) errors, because the received string remains closer to the original codeword than to any other valid one. This is the same geometric idea behind ordinary error-correcting codes, which Richard Hamming helped establish in his foundational [1950 paper](https://doi.org/10.1002/j.1538-7305.1950.tb00463.x).

## Why fixing the weight changes the search

In an unrestricted binary code, each of n positions can independently be zero or one, giving 2ⁿ possible strings. In a constant-weight code, only strings with exactly w ones are allowed. There are “n choose w” such candidates: the number of ways to choose w positions from n. For A(32,12,15), that starting space is much smaller than all 2³² bit strings, but it is still large enough that selecting a maximum separated subset is a difficult combinatorial problem.

The fixed-weight condition also gives a useful distance identity. If two codewords both have weight w, and their sets of 1 positions overlap in r places, then their Hamming distance is 2(w−r). Every position that belongs to only one of the two sets contributes one difference; positions common to both contribute none. Thus constant-weight code construction can be viewed as selecting fixed-size subsets with limited overlap. This connects coding theory to set systems and combinatorial design.

## Construction versus proof of optimality

Suppose a search finds 633 valid codewords for A(32,12,15), and a checker confirms that every word has weight 15 and every pair is at least distance 12 apart. That demonstrates A(32,12,15) ≥ 633. It is a constructive lower bound: here is a concrete object meeting the requirements. It does not establish that 633 is the maximum. There might be a 634-word, 640-word, or even larger code.

To prove the exact optimum, one also needs an upper bound: a rigorous argument that no code satisfying the same rules can have more than 633 words. If construction and upper bound meet, the maximum is known. This is why a table that lists codes of different sizes, or a search that improves an existing construction, should not be described as proving the optimum unless the upper-bound argument is also supplied. The same distinction appears throughout experimental mathematics: finding a witness is often easier than proving no better witness exists.

## How a computer can help

A program can generate candidate words, check their weights, compute pairwise distances, and search for compatible swaps. A common strategy starts from a known code, removes a small subset, and tries replacements that preserve the minimum distance. This can produce a compact patch rather than an opaque giant file. A separate checker can then validate all words and all pairs. For a code with 633 words, there are 200,028 distinct pairs to inspect, since each pair can be counted once.

The checker itself should be simple enough to audit. It should reject duplicate codewords, verify every word has the required weight, and calculate all pairwise Hamming distances. Search output is a candidate; the checker establishes whether that candidate meets the stated definition. A reproducible seed, replacement list, and verification script make the result easier for another person to confirm. An AI agent may help discover a construction, but the mathematical claim remains the same: the artifact and checks must establish the lower bound, and an upper-bound proof is still needed for optimality.

For a wider introduction to the difference between a formal proof and a plausible result, see Ground Truth’s [proof-assistant lesson](https://groundtruth.day/learn/what-is-a-proof-assistant.html). For how test sets can mislead when examples leak into development, see [benchmark contamination](https://groundtruth.day/learn/benchmark-contamination.html); the shared lesson is to state exactly what the evidence establishes.

Constant-weight codes turn a constrained set of bit patterns into a geometry problem: keep every pattern the same size and place them far apart. Their notation makes the requirements precise, while the lower-bound and upper-bound distinction keeps a successful construction from being overstated.

**Key papers**
[Error Detecting and Error Correcting Codes — Richard W. Hamming (1950)](https://doi.org/10.1002/j.1538-7305.1950.tb00463.x)

Key questions

## What makes a code constant-weight?

Every codeword has the same number of 1 bits, called its weight, even though the locations of those 1s differ.

## Why does distance matter in a constant-weight code?

The minimum Hamming distance determines how many bit errors the receiver can detect or correct without confusing one valid codeword for another.

## Does finding a large code prove it is the largest possible?

No. A valid construction proves a lower bound on the maximum size; an optimality claim also needs an upper bound ruling out every larger code.

**Cite this**

APA

```
Ground Truth. (2026, December 5). Constant-weight codes: error-correcting codewords with the same number of ones. Ground Truth. https://groundtruth.day/learn/constant-weight-codes.html
```

BibTeX

```
@misc{groundtruth:constant-weight-codes,
title  = {Constant-weight codes: error-correcting codewords with the same number of ones},
author = {{Ground Truth}},
year   = {2026},
month  = {dec},
url    = {https://groundtruth.day/learn/constant-weight-codes.html}
}
```

Topics: [coding-theory](https://groundtruth.day/tags/coding-theory.html) · [error-correction](https://groundtruth.day/tags/error-correction.html) · [combinatorics](https://groundtruth.day/tags/combinatorics.html) · [mathematics](https://groundtruth.day/tags/mathematics.html)

**Related on Ground Truth**

- [A community hub starts turning OpenAI’s math manuscripts into reviewable work](https://groundtruth.day/news/community-hub-revises-openai-math-manuscripts.html) News
- [A new Lean repository packages RH and Dirichlet GRH proofs in a shorter edition](https://groundtruth.day/news/shorter-lean-formalization-riemann-hypothesis-grh.html) News
- [A newly minted Fields medalist says he is joining OpenAI's safety division](https://groundtruth.day/news/fields-medalist-joining-openai-safety.html) News
- [A record elliptic curve now lists Claude as a collaborator](https://groundtruth.day/news/a-record-elliptic-curve-now-lists-claude-as-a-collaborator.html) News
