liveBook · Manning

Padding

Also called Pad

Padding is the provision of extra values, characters, bytes, or space around or within data or an element to meet length, boundary, block-size, spacing, or alignment requirements.

How 22 Manning books explain it

Hacking Cryptography

A defined method for adding and later removing padding from cryptographic data, potentially incorporating randomness.

How it is used
Fits variable-length plaintext, digest, and signature inputs into fixed-size cryptographic processing units.
How deep it goes
Defines several byte schemes, traces oracle and validation failures, and implements SHA-256 padding for a length-extension exploit.
Examples
Uses an 8-byte final block, PKCS#7 and ANSI X.923 bytes, PKCS#1 v1.5 signatures, and forged HTTP transaction parameters.
What you can do after
Diagnose/debug with it by identifying padding-oracle leaks and enforcing complete structured-padding validation.

Read how Hacking Cryptography explains padding →

Tiny CSS Projects

A CSS property that sets the space between an element's content and its border on each side.

How it is used
Uses padding to keep card text, links, headings, and controls comfortably spaced within their containers.
How deep it goes
Explains side-specific shorthand, contrasts padding with margin, and shows how border-box changes the space available to content.
Examples
Shows padded profile and credit-card faces, checkout-card headers, form controls, and call-to-action links.
What you can do after
Apply it through CSS shorthand or side-specific properties to space content, preserve intended layouts, and reset unwanted browser defaults.

Read how Tiny CSS Projects explains padding →

Inside Deep Learning: Math, Algorithms, Models

How it is used
Preserves convolutional image dimensions and makes differently sized inputs batchable for recurrent and attention models.
How deep it goes
Explains zero padding, a convolution sizing rule, and the steps for padding and packing sequences.
Examples
Uses zero-padded images, padded variable-length sequences, and variable-size sets of inputs.
What you can do after
Apply padding with PyTorch utilities to preserve convolution dimensions or batch variable-length sequences.

Read how Inside Deep Learning: Math, Algorithms, Models explains padding →

Learn Generative AI with PyTorch

A setting or operation that adds, fills, or ignores boundary or placeholder positions in tensor or sequence data.

How it is used
Controls convolution output dimensions and standardizes variable-length sequences for batched Transformer computation.
How deep it goes
Explains convolution and sequence padding through parameterized examples, code, tensor shapes, masks, and calculations.
Examples
Uses a 3 × 3 image, a 2 × 2 filter, padded convolution outputs, token batches, and NumPy sequence-padding code.
What you can do after
Apply padding with PyTorch Conv2d and NumPy batch preparation, then configure masks that ignore padded sequence positions.

Read how Learn Generative AI with PyTorch explains padding →

CSS in Depth, Second Edition

The CSS shorthand property that specifies the space between an element's content and its border.

How it is used
Uses padding to create space within navigation links and containers, distinguishing it from spacing between elements.
How deep it goes
Explains shorthand value order and omitted sides, then works through layout effects rather than providing a complete property reference.
Examples
Builds padded navigation links and compares `1em` padding on elements with different font sizes.
What you can do after
Operate/configure it to size clickable links, choose internal versus external spacing, and prevent unwanted margin collapse.

Read how CSS in Depth, Second Edition explains padding →

Build a Website with ChatGPT

The CSS padding shorthand property sets padding values for multiple sides of an element with one declaration.

How it is used
Adds space around content inside an element’s box so page content feels less crowded.
How deep it goes
Defines padding within the box model and demonstrates side-specific and shorthand declarations, without exploring browser layout internals.
Examples
Shows four-value header padding, single-value body padding, and a prompt requesting footer padding.
What you can do after
Operate/configure it by changing CSS padding values to adjust space around page content.

Read how Build a Website with ChatGPT explains padding →

Natural Language Processing in Action, Second Edition

Padding is the addition of extra positions around an input sequence so boundary regions can be processed and output dimensions controlled.

How it is used
Standardizes text sequences before embedding and convolution so CNN encodings retain consistent dimensions.
How deep it goes
Explains filler tokens, clipping, sequence-length effects, and implementation, but does not develop padding strategies beyond fixed-length sequences.
Examples
Uses a reusable Python padding function, a ten-word convolution example, and a CNN configured for sequences of length 40.
What you can do after
Build it from scratch by clipping sequences, appending a pad token, and sizing the downstream CNN tensors.

Read how Natural Language Processing in Action, Second Edition explains padding →

Math and Architectures of Deep Learning

The treatment of positions where a convolution kernel extends beyond the input array, such as stopping early or pretending missing values are zero.

How it is used
Controls convolution boundaries and output dimensions while preserving or reducing spatial extent.
How deep it goes
Defines valid and zero padding, derives output-size reasoning, and connects padding to PyTorch parameters.
Examples
Uses size-3 kernels on one-dimensional arrays, boundary figures, output-size equations, and PyTorch Conv1d listings.
What you can do after
Apply it via PyTorch by selecting padding alongside kernel size and stride in a convolution layer.

Read how Math and Architectures of Deep Learning explains padding →

100 Go Mistakes and How to Avoid Them

Padding is the insertion of extra memory space between data fields to control their placement and alignment.

How it is used
Uses padding to explain struct alignment and to prevent false sharing between concurrent field updates.
How deep it goes
Works through byte-level struct layouts, cache-line separation, and a benchmark comparison with a communication alternative.
Examples
Compares a byte–int64–byte struct with a reordered layout and two goroutines updating separate result fields.
What you can do after
Evaluate struct layouts and false-sharing risks, then choose padding, field reordering, or communication as appropriate.

Read how 100 Go Mistakes and How to Avoid Them explains padding →

Grokking AI Algorithms, Second Edition

Padding is the addition of extra border values around an input array before an operation is applied.

How it is used
Preserves convolutional spatial dimensions and lets filters process image borders and corners.
How deep it goes
Explains zero borders, edge coverage, and output sizing, then demonstrates 2D and 3D implementations without deeper convolution theory.
Examples
Uses a 3×3 filter scan, zero-padded image, NumPy functions, and a padded multi-channel tensor.
What you can do after
Builds padding from scratch for 2D images and 3D feature-map tensors using zero-filled borders.

Read how Grokking AI Algorithms, Second Edition explains padding →

Software Security for Developers

Padding is the addition of extra data so that an input conforms to a required fixed block size or cryptographic encoding format.

How it is used
Explains how cryptographic inputs meet fixed-size AES blocks and how RSA encryption gains protection from randomized encoding.
How deep it goes
Demonstrates block sizing and contrasts RSA schemes, but stops short of specifying padding bytes or implementing padding code.
Examples
Uses a 1,605-byte AES message and RSA comparisons between OAEP and PKCS#1 v1.5.
What you can do after
Evaluate padding choices by matching AES block requirements and preferring OAEP over RSA PKCS#1 v1.5.

Read how Software Security for Developers explains padding →

Grokking GPU Programming

Padding adds extra elements to a data structure, commonly with neutral values, to meet an algorithm's size requirements.

How it is used
Reduces shared-memory bank conflicts in column-oriented tiles and supplies identity-valued slots when Blelloch scans require power-of-two sizes.
How deep it goes
Shows how a spacer column shifts bank alignment, quantifies its memory cost, and cautions that other element sizes may need different mappings.
Examples
Uses a four-bank 4 × 4 array, a 32-bank 32 × 32 tile, and a six-element scan padded with zeros.
What you can do after
Apply it by adding a spacer column to a column-accessed tile or identity values to a power-of-two scan input.

Read how Grokking GPU Programming explains padding →

Deep Learning with R, Third Edition

Padding is the addition of rows and columns around an input feature map so convolution windows can cover boundary locations.

How it is used
Uses padding to preserve convolutional spatial dimensions and rectangularize variable-length text batches.
How deep it goes
Defines boundary and sequence padding with concrete dimensions and API choices, but defers detailed masking and convolution arithmetic.
Examples
Uses 5 × 5 feature maps, 3 × 3 windows, padded IMDb reviews, and an R/Keras TextVectorization pipeline.
What you can do after
Apply padding through Conv2D modes or TextVectorization output_sequence_length when constructing image and text pipelines.

Read how Deep Learning with R, Third Edition explains padding →

Real-World Cryptography

Padding is the addition of structured data to an input so it can be divided into required-size blocks while preserving input boundaries.

How it is used
Uses structured bytes to align cipher and hash inputs, recover message boundaries, and sometimes conceal plaintext length.
How deep it goes
Explains reversible PKCS#7 rules, hash preprocessing, and TLS length-hiding tradeoffs without descending into implementation details.
Examples
Demonstrates eight-byte AES padding, PKCS#7 full-block padding, SHA-256 block preparation, and TLS record length hiding.
What you can do after
Apply it via established padding rules when preparing block-cipher or hash inputs, while recognizing that length hiding remains imperfect.

Read how Real-World Cryptography explains padding →

Web Design Playground, Second Edition

A padding shorthand property is a CSS declaration form that specifies multiple padding side values in one property.

How it is used
Uses padding shorthand to create whitespace inside element boxes and improve readability, grouping, and navigation spacing.
How deep it goes
Defines padding, lists its units and side properties, demonstrates a four-value shorthand, and stops short of deeper layout theory.
Examples
Demonstrates a pull quote and a horizontal navigation menu with added item spacing.
What you can do after
Build it from scratch by writing compact padding declarations for content boxes, pull quotes, and navigation items.

Read how Web Design Playground, Second Edition explains padding →

Deep Learning with Python, Third Edition

How it is used
Preserves feature-map dimensions by extending inputs so convolution windows can cover border tiles.
How deep it goes
Works through 3 × 3 and 5 × 5 window examples and names Conv2D options and defaults.
Examples
Compares a 5 × 5 feature map with 3 × 3 windows, then describes padding for 3 × 3 and 5 × 5 windows.
What you can do after
Configure Conv2D with valid or same padding to control whether output dimensions shrink or match the input.

Read how Deep Learning with Python, Third Edition explains padding →

Web Design Playground

The inner spacing between an element's content and its border.

How it is used
Adds breathing room inside element boxes and helps keep navigation labels visually distinct.
How deep it goes
Explains padding’s box-model position, four side properties, measurement units, and shorthand through CSS rules.
Examples
Uses a pull quote with four unequal padding values and an inline-block navigation list with right padding.
What you can do after
Apply it via CSS side properties or shorthand to space content within its box and separate navigation labels.

Read how Web Design Playground explains padding →

Rearchitecting LLMs

Padding is the addition of extra elements to a computational dimension so its size meets a hardware or algorithmic alignment requirement.

How it is used
Reduces wasted GPU work when selecting feed-forward widths during pruning.
How deep it goes
Explains tile alignment and quantifies its cost with a pruning example and Python helpers.
Examples
Calculates padding for a 6,553-wide target and compares it with snapping to 6,528.
What you can do after
Apply the Python helpers to estimate padding waste or snap a pruned width to an aligned boundary.

Read how Rearchitecting LLMs explains padding →

LLMs in Production

Padding is the addition of placeholder elements to sequences so that inputs in a batch share a common length.

How it is used
Supports batch tokenization and recurrent-model processing by equalizing variable-length input sequences.
How deep it goes
Defines placeholder-token padding and maximum-length extension, but defers masking and detailed padding strategies.
Examples
Uses a <PAD> tokenizer token and packed embeddings extended to the longest sequence in a Twitter sentiment dataset.
What you can do after
Apply it via Hugging Face tokenizers or packed embeddings to prepare variable-length sequences for batch processing.

Read how LLMs in Production explains padding →

Design for Developers

Padding is the internal space between an element's content and its border or edge.

How it is used
Uses padding to maintain consistent vertical rhythm across typography and interface components.
How deep it goes
Explains padding through baseline multiples and a body-copy calculation, but stops short of component-specific implementation.
Examples
Demonstrates 16px top spacing with 20px line height to reach a 36px baseline-compatible total.
What you can do after
Apply padding using baseline multiples and check its effect on typographic alignment and readability.

Read how Design for Developers explains padding →

Modern C, Third Edition

Byte padding is unused whole-byte storage inserted within or after a structure to satisfy layout or alignment requirements.

How it is used
Explains wasted storage and alignment effects in structure layout.
How deep it goes
Defines placement rules and reduction by member ordering, while deferring alignment details to a later treatment.
Examples
Uses a person structure layout and contrasts byte padding with compact time-related bit-field declarations.
What you can do after
Evaluate structure layouts and reduce potential waste by considering member order.

Read how Modern C, Third Edition explains padding →

Math for Web Design

The CSS padding property specifies the space between an element's content and its border.

How it is used
Uses padding to create content-to-border space and calculate predictable element dimensions in fixed, inherited, percentage, and responsive layouts.
How deep it goes
Calculates box dimensions, containing-block percentages, inheritance behavior, and fluid values, but stops short of browser implementation internals.
Examples
Uses fixed-width boxes, inherited percentages, parent-width calculations, and clamp-based fluid gutters as concrete examples.
What you can do after
Diagnose sizing surprises and apply fixed, inherited, percentage, or fluid padding using explicit CSS calculations.

Read how Math for Web Design explains padding →

Also covered in

What to know first

Related concepts

Questions about padding

What is padding?

Padding is the provision of extra values, characters, bytes, or space around or within data or an element to meet length, boundary, block-size, spacing, or alignment requirements.

Which Manning books explain padding?

Hacking Cryptography, Tiny CSS Projects, Inside Deep Learning: Math, Algorithms, Models, Learn Generative AI with PyTorch, CSS in Depth, Second Edition, Build a Website with ChatGPT, Natural Language Processing in Action, Second Edition, Math and Architectures of Deep Learning and 14 more.

What should I know before learning padding?

Manning books that teach padding usually introduce array, embedding, CSS and input first.

What is the difference between padding and margin property?

Padding is the provision of extra values, characters, bytes, or space around or within data or an element to meet length, boundary, block-size, spacing, or alignment requirements. The CSS margin property specifies the outer space around an element’s border, separating it from neighboring content.

What kinds of padding are there?

Kinds of padding include dynamic padding.

What is padding a kind of?

Padding is a kind of style property. A style property is a named setting or interface attribute that specifies or exposes a presentation characteristic of an element or view.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.