§1.2
PCM parameters and byte order
Pulse Code Modulation (PCM) represents a signal as measurements taken at fixed
intervals. Reading a PCM stream requires its sample rate, sample format, channel count, and
byte order.
The name comes from 1930s telephony, where it described a way of sending a signal down a
line rather than a way of storing it. Related methods carried the signal on a train of pulses by
varying one property of each pulse: its height in pulse-amplitude modulation, its width in
pulse-width modulation, its timing in pulse-position modulation. PCM instead converted each
measurement to a binary code and sent that code as a group of on-or-off pulses. The
signal modulates the pulse train, the pulses carry a code, hence the name. The
transmission part is no longer relevant, and the term now refers to the representation itself:
one encoded number per sample.
Sample rate is the number of measurements per second. Half the rate is the
upper frequency boundary for reconstruction. Sample format specifies the bit
depth and representation: signed or unsigned integer, or floating point. It determines the
available levels and dynamic range. Channel count specifies the
number of simultaneous streams. Interleaved stereo stores left and right samples in alternating
order. Values wider than 8 bits also have a byte order. Standard WAV PCM is
little-endian; AIFF PCM is big-endian. Reading samples in the wrong byte order can produce loud
noise.
From voltage to PCM: range and input gain
An analogue-to-digital converter (ADC) measures a changing electrical voltage. A microphone
converts sound pressure into voltage, and a preamp amplifies that signal before conversion.
The converter's circuitry and voltage reference set its input range; the corresponding PCM
amplitudes are commonly normalised to approximately −1 to +1.
For example, the PCM1808 ADC accepts a
3 V peak-to-peak signal: ±1.5 V around its centre voltage. A signal voltage of +0.75 V relative
to that centre therefore maps to about +0.5. Bit depth determines how finely this voltage
range is divided into codes.
The recording interface's input-gain control changes the amplification
before the ADC. Set it so the loudest expected peaks fit within the range, with spare room
for louder moments. Peaks around −12 dBFS are a useful starting point.
Too much gain overloads the input; reducing the recorded numbers later
cannot restore clipped peaks. A PCM sample alone does not specify the original sound pressure:
that also depends on the microphone's sensitivity and the recording gain.
The next section examines the sample format in more detail: how bit
depth sets the available values, and how choosing one of those values introduces quantisation
error. Companding then changes the spacing of those values.
Byte order
A 16-bit sample occupies two bytes, and a format must state which byte
comes first. Little-endian stores the least significant byte first;
big-endian stores the most significant byte first. The value 4660, or
0x1234, is stored as the bytes 34 12 in little-endian order and
12 34 in big-endian order. x86 and most ARM systems are little-endian, as is WAV.
Network protocols and AIFF are big-endian. The names come from Gulliver's Travels,
where two factions dispute which end of an egg to open. Reading with the wrong order swaps
the two bytes of every sample, so the low byte, which changes from one sample to the next,
becomes the high byte. The waveform becomes a sequence of large jumps, heard as loud
broadband noise. Single-byte formats have no byte order.
Multiplying sample rate, bits per sample, and channel count gives the bitrate. Dividing by
eight gives bytes per second:
package main
import "fmt"
func main() {
sampleRate := 44100 // samples per second: CD audio
bits := 16 // bits per sample
channels := 2 // stereo
bytesPerSecond := sampleRate * (bits / 8) * channels // bits/8 = bytes per sample
fmt.Println(bytesPerSecond, "B/s") // 176400 B/s = 1.41 Mbit/s, or 10 MB per minute
}
const sampleRate = 44100; // samples per second: CD audio
const bits = 16; // bits per sample
const channels = 2; // stereo
const bytesPerSecond = sampleRate * (bits / 8) * channels; // bits/8 = bytes per sample
console.log(bytesPerSecond, "B/s"); // 176400 B/s = 1.41 Mbit/s, or 10 MB per minute
Figure 1 · live
PCM parameters and data size
The sliders show the waveform being sampled and rounded, and the resulting size in bytes.
the original signal
stored values
quantisation levels
Highest frequency
22050 Hz
✓
Sample rate sets the frequency range. Bit depth sets the quantisation step size and affects the
noise floor. "Distinct levels" is the number of values the sample integer can hold, 2 to the power
of the bit depth: 256 at 8 bits, 65,536 at 16 bits, about 16.8 million at 24 bits. Every stored
value is one of these levels. Adjust each slider to compare changes in the sampled waveform and
data size.
Common sample rates
| Rate | Use and background |
| 8 kHz | Telephony. Speech is intelligible with about 4 kHz of bandwidth,
so 8 kHz is the smallest rate that carries it. |
| 44.1 kHz | CD audio. The rate comes from early digital recorders that stored audio on video tape, where
each video field had to contain a whole number of samples. |
| 48 kHz | Professional video and general audio production. Its relationship to common frame rates
simplifies alignment between audio and picture. |
| 96 / 192 kHz | Production formats. Higher rates allow wider transition bands for anti-aliasing and
reconstruction filters and provide headroom for signal processing. |
Sample rate and aliasing
Frequencies above half the sample rate can alias into the representable band,
producing tones at different frequencies. An anti-aliasing filter limits the input bandwidth
before sampling. The companion explainer on the sampling theorem covers
this process in detail.
§1.3
PCM sample format: bit depth and quantisation
The sample format introduced in §1.2 specifies how each
PCM measurement is encoded as a number. In linear integer PCM, a sample with
b bits has 2b possible values, representing evenly spaced amplitude
levels. Quantisation is choosing which of those levels to store; here we round
to the nearest one. Bit depth sets the number of choices.
For example, signed 16-bit PCM stores each sample as a two-byte integer from −32,768 to
32,767. Dividing that integer by 32,768 gives its amplitude on the plot's normalised scale.
An input amplitude of 0.1 becomes round(0.1 × 32768) = 3277. Reading the stored
sample back gives 3277 / 32768 ≈ 0.1000061. The difference from 0.1 is the
quantisation error.
Changing the PCM format from 16-bit to 24-bit integer places the levels closer together at
the same full-scale amplitude, reducing that rounding error. It does not change the number of
samples per second. The evenly spaced levels below describe linear integer PCM; companded
and floating-point formats distribute their values differently.
The quantisation step is the distance between two neighbouring levels. For a
range of −1 to +1 and b bits it is 2 ÷ 2b: 0.125 at 4 bits, about
0.00003 at 16 bits. It is also called one LSB, for least significant bit, since it is the change
produced by flipping the lowest bit of the sample. Rounding a sample to the nearest level
introduces an error bounded by half a step. Each additional bit halves the step size. When the
rounding error behaves as uniformly distributed noise, this lowers the noise floor by about 6 dB
per bit:
dynamic range≈6.02b+1.76 dB
- b
- bits per sample.
- 6.02
- one extra bit doubles the number of levels; doubling is 6.02 dB.
- 1.76
- a constant arising from the power ratio between a full-scale sine and uniformly distributed
rounding error.
The approximate range is 50 dB for 8-bit audio, 96 dB for 16-bit audio, and 144 dB for 24-bit
audio. Recording and production commonly use 24-bit samples to accommodate low recording levels
and repeated processing. The usable range of a recording also depends on microphone noise,
converter performance, and the recording environment.
dBFS
Signal levels on this page are given in dBFS, decibels
relative to full scale. For integer PCM, full scale is the limit of the representable amplitude range,
approximately ±1.0 in the figures, and a signal whose peaks reach it is at 0 dBFS. Quieter signals have negative values:
the level is 20·log10(amplitude ÷ full scale), so −6 dBFS is half the amplitude,
−20 dBFS one tenth, and −60 dBFS one thousandth. The unit makes levels and bit depth directly
comparable. Each bit adds about 6 dB, so the quantisation noise of a 16-bit format sits near
−96 dBFS, and a tone at −90 dBFS is about 6 dB above it.
Quantisation error as an added signal
Bit depth is sometimes described as the precision of each sample, as if a 24-bit recording were
a sharper copy of a 16-bit one. A more useful description treats the rounding error as a second
signal added to the first: the stored value minus the true value, which is the orange trace in
Figure 2. Its size is always within half a step, so bit depth alone does not determine how
audible it is. Its character does, and the character depends on the signal.
A loud or complex signal crosses many levels in an irregular sequence, so the error at each
sample is effectively random. Random error is noise. It sits at a fixed level, about 6 dB lower
for each additional bit, and is heard as faint hiss. This is the usual case, and it is what "bit
depth sets the noise floor" refers to. A quiet or simple signal crosses the same one or two
levels in the same way on every cycle, so the error repeats with the signal. Repeating error is
distortion: tones at multiples of the signal's frequency that were not in the source, which
hearing detects more readily than noise of the same power. Figure 2 shows this near −20 dBFS. A
signal smaller than half a step rounds to zero at every sample and is removed entirely.
Bit depth changes only the step size. Finer steps reduce the maximum error and lower the noise
floor, while full scale stays where it is. Bit depth therefore sets the floor rather than the
ceiling, and dynamic range is the distance between the loudest representable signal and the
rounding noise beneath it. Low bit depths are exposed by quiet passages rather than loud ones.
PCM's sample rate and sample format control different parts of this process. Sampling takes
measurements at the instants set by the sample rate. Quantisation maps their amplitudes to
values allowed by the sample format. The sampling page explains why
sufficiently frequent samples preserve a bandlimited signal. Quantisation introduces an
amplitude error whenever a measurement falls between the available levels.
Figure 2 · audio + live
A signal and its quantisation error
The signal is encoded as linear integer PCM by rounding to the nearest of its
2bits amplitude levels. Top: the original and
the rounded version, with the levels drawn as dashed lines; the vertical axis zooms in as the
signal gets quieter. Bottom: the rounding error, rounded minus original, measured in
quantisation steps. Rounding is never off by more than half a step, so the error's size is
fixed and its shape is what changes. Lower the signal level and watch the shape. The
buttons play the signal at the selected level and bit depth, with the dither checkbox applied.
Playback gain is normalised so quiet settings remain audible; compare the character of the
sound rather than its loudness. A steady sine repeats every cycle, so its rounding error is
periodic at any level. The two-tone signal, 440 and 623 Hz, never repeats, so its error can
behave as noise.
original
after rounding
error: rounded minus original, in steps
✓
At 0 dBFS with 4 bits the sine spans 8 steps and crosses every level. The error is a
rapid sequence of small ramps, one per level crossing, and resembles random noise. This is the
regime the 6 dB-per-bit estimate describes. Near −20 dBFS the sine spans less than one step, the
rounded output becomes a two- or three-level square wave, and the error becomes a periodic
waveform locked to the signal. That error is distortion: harmonics of the signal that were not in
the source. Below about −24 dBFS the amplitude is under half a step, every sample rounds to zero,
and the error is the negative of the signal. "Levels used" counts how many levels the rounded
output lands on. With dither enabled, random noise is added before rounding, the output flickers
between neighbouring levels in proportion to the input, and the error loses its lock to the
waveform. With the single sine, the full-scale error is a dense set of harmonics and is heard as a
change of timbre. With the two tones, the full-scale error decorrelates and plays as broadband
hiss, while the low-level error still collapses into distortion.
Clipping at full scale
Quantisation rounds values within the available range. Clipping happens when
a value exceeds that range and is limited to the largest or smallest available code. Signed
16-bit PCM runs from −32,768 to 32,767; signed 24-bit PCM runs from −8,388,608 to 8,388,607.
Divide by 32,768 or 8,388,608 respectively and both cover the same normalised range, from −1
to just below +1. 24-bit PCM has finer steps, but the same full-scale ceiling.
Suppose a waveform peaks at 0.75. Doubling its gain asks the PCM encoder to store peaks of
1.5. A clipping encoder stores the maximum code instead, flattening the peaks. The waveform
now contains harmonics that were absent from the input, heard as a harsher or buzzing tone.
This is overload distortion, not the small rounding error between neighbouring levels.
Reducing the level after clipping makes the damaged waveform quieter; it cannot
restore the missing peaks. Leave headroom below full scale when recording, and reduce gain
before conversion to an integer format if processing has pushed values beyond its range.
Clipping · audio + live
More bits do not prevent overload
A 440 Hz sine starts with a peak amplitude of 0.75. Increase its gain to push the blue
waveform past full scale; orange shows the samples after conversion to integer PCM.
Compare 16 and 24 bits: both flatten at the same level.
before conversion
after integer PCM conversion
full-scale limits (±1)
Choose a version to hear it.
Peak before conversion
1.50
Samples outside the range
—
PCM integer limits
−32,768 to 32,767
At ×1, neither format clips and the two versions sound alike. At ×2, listen for
the added harmonics, then switch to 24 bits: more precision does not repair an overloaded
signal. Both versions receive the same playback attenuation after processing, so the
comparison is audible without overloading the output. Each clip lasts three seconds; changing
a setting stops playback so you can replay the new setting.
32-bit floating-point PCM
PCM can also store each sample as a four-byte
IEEE 754 floating-point number. Its bits are
divided into 1 sign bit, 8 exponent bits, and 23 fraction bits. For normal
values, an implicit leading 1 gives 24 bits of significant precision. The exponent moves the
scale up or down, rather like the power of ten in scientific notation. The spacing between
representable values grows with magnitude, unlike the fixed steps of integer PCM.
In floating-point audio, ±1 still marks the nominal full-scale level, but it is not the
storage limit. A value of 1.5 is valid and can later be reduced to 0.75 without having clipped.
This extra headroom is useful during mixing and processing. It is not 32 bits of integer
precision, and arithmetic still rounds to the available floating-point values.
The example follows the same sample through two paths. Keeping the boosted value as a
float preserves the peak. Converting it to 16-bit PCM first clips it, so halving the gain
afterwards returns about 0.5 instead of 0.75. It also prints the float's three bit fields:
for 1.5, the sign is 0, the stored exponent is 127, and the fraction encodes 0.5. Subtracting
the exponent bias of 127 gives +(1 + 0.5) × 2⁰ = 1.5.
package main
import (
"fmt"
"math"
)
// Round and clamp a finite normalised value before converting to PCM16.
func pcm16(x float32) int16 {
q := math.Round(float64(x) * 32768)
q = math.Max(-32768, math.Min(32767, q))
return int16(q)
}
func main() {
sample := float32(0.75)
boosted := sample * 2 // 1.5 fits in float32
restored := boosted / 2 // 0.75: peak preserved
clipped := pcm16(boosted) // 32767: peak lost
afterClip := float32(clipped) / 32768 / 2
fmt.Printf("Float path: %.6f -> %.6f\n", boosted, restored)
fmt.Printf("PCM16 first, then gain down: %.6f\n", afterClip)
word := math.Float32bits(boosted) // inspect the IEEE 754 representation
fmt.Printf("sign exponent fraction: %01b %08b %023b\n",
word>>31, (word>>23)&255, word&0x7fffff)
}
// JavaScript numbers are float64; fround models float32 storage.
const f32 = Math.fround;
// Round and clamp a finite normalised value before converting to PCM16.
function pcm16(x) {
const q = Math.sign(x) * Math.round(Math.abs(x) * 32768);
return Math.max(-32768, Math.min(32767, q));
}
const sample = f32(0.75);
const boosted = f32(sample * 2); // 1.5 fits in float32
const restored = f32(boosted / 2); // 0.75: peak preserved
const clipped = pcm16(boosted); // 32767: peak lost
const afterClip = f32(f32(clipped / 32768) / 2);
console.log(`Float path: ${boosted.toFixed(6)} -> ${restored.toFixed(6)}`);
console.log(`PCM16 first, then gain down: ${afterClip.toFixed(6)}`);
const view = new DataView(new ArrayBuffer(4));
view.setFloat32(0, boosted); // inspect the IEEE 754 representation
const word = view.getUint32(0);
const bits = (value, width) => value.toString(2).padStart(width, "0");
console.log("sign exponent fraction:",
bits(word >>> 31, 1), bits((word >>> 23) & 255, 8), bits(word & 0x7fffff, 23));
This protects values only while they remain in a floating-point processing path. Reduce
gain before exporting to integer PCM or sending the signal to an output with a fixed
full-scale limit. A microphone, preamp, or analogue-to-digital converter can still overload;
writing its already-clipped samples into a float file cannot restore them.
| PCM sample format | Range | Where it appears |
| 8-bit linear | ~50 dB | Legacy audio and sound effects. Quantisation noise can be audible in quiet passages. |
| 8-bit µ-law / A-law | ~14 bits' worth | Telephony. Non-uniform levels provide finer resolution for quiet signals — see §1.4. |
| 16-bit signed | ~96 dB | CD audio and common delivery formats. Full scale is 0 dBFS; lower levels have negative dBFS
values. |
| 24-bit signed | ~144 dB | Recording and production. Additional range for low-level signals and processing. |
| 32-bit float | very large | Mixing and mastering. ±1.0 corresponds to 0 dBFS. Floating-point storage can retain values
beyond that level for later gain reduction. |
Go deeper Where 6.02 and 1.76 come from
With b bits the step size is q=2/2b for a signal spanning −1 to +1.
Assume the rounding error is uniformly distributed across ±q/2 as an approximation for signals that cross many levels. A uniform distribution of width q has variance
q2/12, so the noise power is q2/12.
A full-scale sine has power 1/2. The ratio is
q2/121/2=2q212=23⋅22b, and
10log10(2322b)=20blog102+10log101.5=6.02b+1.76
dB. The constant 1.76 equals 10log10(3/2), using the sine's RMS power as the signal reference.
This estimate assumes uniformly distributed error that is uncorrelated with the signal. Quiet
or simple signals can produce repeating error patterns, limiting the estimate's usefulness for
low-level behaviour. Appropriate dither removes the signal dependence of the error's mean and
variance.
§1.4
Companding and non-uniform quantisation
PCM's sample format also determines how its stored codes map to amplitudes. Linear 8-bit
PCM uses evenly spaced levels and provides about 50 dB of range. Telephony uses 8-bit
companding formats to represent a wider range of speech levels by varying that
spacing. Each sample still occupies one byte; the meaning of its code changes.
Hearing responds roughly to proportional changes in amplitude. Increasing an amplitude from
0.001 to 0.002 adds only 0.001, while increasing it from 0.5 to 1.0 adds 0.5. Both changes,
however, double the starting amplitude: each is a 100% increase. Both correspond to about
+6 dB. This is the reason for describing levels on a logarithmic scale: equal ratios give equal
changes in decibels. Doubling the amplitude does not mean doubling the perceived loudness.
The same distinction matters for rounding. Consider a quantiser whose allowed values are
spaced 0.01 apart and include zero. A quiet sample of 0.002 rounds to 0, an error equal to 100%
of its original value. A larger sample of 0.502 rounds to 0.50, an error of about 0.4%. The
absolute error is 0.002 in both cases, but it is much larger relative to the quiet sample.
With evenly spaced levels, quiet signals have fewer nearby values to round to. A signal whose
peak amplitude stays below half a step rounds entirely to zero when each sample is rounded to
the nearest level. Finer steps near zero reduce this loss and the rounding error in quiet signals.
Companding allocates the available values unevenly: levels are closer together near silence
and farther apart at larger amplitudes. With the same total number of values, this provides
finer precision for quiet signals at the cost of coarser precision for loud ones.
µ-law (North America and Japan) and A-law (elsewhere) use
approximately logarithmic spacing: fine steps near silence and coarse steps near full scale.
Each sample still occupies one byte, with 256 possible values. Their smallest steps provide
finer low-level resolution than 8-bit linear PCM.
Figure 3 · live
Even spacing versus logarithmic spacing
Compare linear, µ-law, and A-law coding with the same number of values. The "level spacing"
view maps evenly spaced codes to amplitudes; ticks show the resulting levels. The "quality vs
level" view estimates the signal-to-noise ratio from the local step size. Only positive
amplitudes are shown; the negative half is symmetric. Use the 16-bit preset to compare a
common modern linear PCM format with the low-bit-depth examples.
linear — evenly spaced
µ-law — logarithmic
A-law — linear near zero, then logarithmic
common modern PCM format
view
6-bit illustration. Modern linear PCM commonly uses 16 or 24 bits per sample.
µ-law equivalent bits
11.5
A-law equivalent bits
10.0
Linear coding has finer resolution for loud signals; both companding curves allocate
finer steps to quiet signals. A-law uses equally spaced steps in a small region around zero,
then increases their spacing logarithmically. µ-law allocates still finer steps near zero.
"Equivalent bits" compares each curve's near-zero step with a linear quantiser's step: at
8 bits, about 13.5 bits for µ-law and 12 bits for A-law. The range readouts use the same
near-zero estimate; they do not describe precision at every amplitude. The figure uses
ideal companding curves
with µ = 255 and A = 87.6. Modern linear PCM commonly uses 16 or 24 bits; the 16-bit setting
has 65,536 levels and uses two bytes per sample. Telephone µ-law and A-law use 8-bit samples;
their curves at other bit depths are illustrative. At high bit depths, many level ticks share
the same screen pixel and merge into bands.
Companding changes the mapping between sample values and amplitudes while keeping the sample
count and byte count fixed. It is a form of perceptual coding: precision is
allocated according to hearing sensitivity. Gamma encoding and chroma subsampling apply related
principles to images.