DEV Community

Cover image for What Are Buffers, Really?
Hossein Naseri
Hossein Naseri

Posted on

What Are Buffers, Really?

Buffers are temporary memory spaces used to hold data while it is being moved from one place to another.

Think of it like eating rice.

You cannot move the entire plate of rice into your stomach at once.
So you use a spoon.

The spoon temporarily holds a small piece of rice,
moves it,
Then it gets filled again.

In computers, buffers work similarly.

Instead of moving huge amounts of data all at once, computers usually move data in smaller chunks.

A buffer temporarily stores those chunks while data is being:

  • copied
  • read
  • written
  • uploaded
  • downloaded
  • streamed

For example:

  • while reading a file
  • while streaming a video
  • while receiving internet packets
  • while copying data between memory and disk

Buffers help data move smoothly and efficiently.

What Is a Buffer Technically?

<Buffer 4C A1 33 00 00 ...>
Enter fullscreen mode Exit fullscreen mode

A buffer is a block of raw binary data stored in memory.

You can think of it as a list of very small memory units called bytes.

Each item inside a buffer:

  • has exactly 8 bits (1 byte)
  • stores a small piece of data
  • can be read, changed, copied, or written

For example:

4C A1 33 00

Each pair represents one byte of data written in **hexadecimal **format.

Why and What Is Hexadecimal?

We will learn more about hexadecimal later, but for now, here is the basic idea.
Computers internally work with binary numbers:

01001100 01001100 01001100 01001100

But binary is difficult for humans to read and understand quickly.

Imagine looking at thousands of bytes written only with 0s and 1s.
It becomes confusing very fast.

So programmers use hexadecimal instead.

Hexadecimal is simply a shorter and cleaner way to represent binary data.

For example, instead of writing:

01001100

we can write:

4C

Both represent the same data.

Simple Mental Model

Think of a buffer like this:

[ byte ][ byte ][ byte ][ byte ]

Each box:

  • contains 8 bits
  • stores a tiny piece of data
  • together forms larger information

That is the core idea behind buffers.

Top comments (0)