# How do buffers work?

**URL:** <https://forum.makecode.com/t/how-do-buffers-work/44161>\
**Category:** Arcade\
**Tags:** game, demo\
**Created:** [May 25, 2026, 9:39pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161 "2026-05-25T21:39:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheEarth](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theearth/32/34579_2.png) [@TheEarth](https://forum.makecode.com/u/TheEarth)\
**Post date:** [May 25, 2026, 9:39pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/1 "2026-05-25T21:39:41Z")

</div>

I see some big brained people like @richard @WoofWoof (w new title) use them but I wanna know how to use them in makecode and the purpose of em

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [May 25, 2026, 9:44pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/2 "2026-05-25T21:44:52Z")

</div>

Buffers in MakeCode provide a way to work with large amounts of data.

I use them in projects like [What’s My Word](https://forum.makecode.com/t/introducing-whats-my-word/11998) and [Countdown Solo](https://forum.makecode.com/t/alexks-dev-blog/18443/25) to store the word lists. I’m also working on an implementation of the [Z-Machine](https://en.wikipedia.org/wiki/Z-machine) to play games like Zork, where I’m using buffers to manipulate the system’s main memory.

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [May 26, 2026, 2:07am UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/3 "2026-05-26T02:07:54Z")

</div>

on my 3D voxel engine topic me and richard talk about them a bit, you could look there a bit

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [May 26, 2026, 2:15am UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/4 "2026-05-26T02:15:00Z")

</div>

Buffers are like arrays but each element in a buffer is just one byte (8 1s/0s) so generally you just use them if you are working with a lot of data and don’t want to waste a ton of memory working with them. You cannot simply add elements to them like you can with an array, you must define it first with the amount of memory you’re going to use.  
They are generally simpler and smaller amounts of memory to handle and have way fewer edge cases and opportunities for bugs when compared to a normal number array, so they are used when interacting with many built in MakeCode features, for example sound instructions, the color palette, and font data, so knowing how they work can be quite useful, though you can often find extensions that let you do those things without having to ever touch buffers yourself.  
There are many ways to write numbers larger than the 1 byte by simply using 2 bytes or more, though I don’t often find myself needing to do that.  
The main thing I use them for is the ability to create them from Base64 or hex strings and to generate those strings from them, which is useful if you want to be able to copy data from the console and save it for later.  
I suppose you could start in Makecode by just creating a buffer with code like `let b = Buffer.create(10)` and then messing around with it and going down the list of suggested functions that come up after you type `b.`  
Keep in mind you can also access them like an array with [] like `b[] = 1` though this will assume you are writing/reading with a UInt8 format, aka “unsigned” (no negative numbers) “integer” “8” (only 8 bits per element) so only numbers 0-255 can be written/read this way. If you write, say, -2, it wraps around and reading it will result in 254. At a certain point you get into bitwise operations, which I’ll let you look up on your own… this post is long enough I think :)

---

<div class="post-metadata">

**Author:** ![NeverStopTheCoder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/neverstopthecoder/32/21194_2.png) [@NeverStopTheCoder](https://forum.makecode.com/u/NeverStopTheCoder)\
**Post date:** [May 26, 2026, 11:30pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/5 "2026-05-26T23:30:19Z")

</div>

can you store a image using a buffer so I can do like #asga72#gwf or like a code that stores that image

---

<div class="post-metadata">

**Author:** ![YamJam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yamjam/32/29681_2.png) [@YamJam](https://forum.makecode.com/u/YamJam)\
**Post date:** [May 26, 2026, 11:30pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/6 "2026-05-26T23:30:25Z")

</div>

Maybe someday I’ll be able to understand this or whatever you mean by one byte, whatever a Base64 and hex strings are, and what exactly you would use them for. 😥

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [May 26, 2026, 11:56pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/7 "2026-05-26T23:56:30Z")

</div>

Hex and base64 strings are just strings of numbers and letters that represent raw data in a way that can be easily copy and pasted, which is why they are convenient. They help with storing large amounts of data in a text based format. If you look into the explorer at the image and music files (you’ll have to create an image and a song to see these) you’ll see that the image assets and the songs you create are stored as long strings of random gibberish, which are base64 strings. Hex strings are also useful but store less information per character on account of using only 16 characters instead of the 64 used in Base64.

1 byte is 8 bits, a bit is a single 1 or 0 in your computer memory. These 1s and 0s are chunked into sections that are 8 long, and that string of 8 bits is called a byte. There are 1 million bytes in a Megabyte, for example, which means 8 million 1s and 0s.  
Memory is usually handled in bytes, meaning numbers stored in a single byte are fairly space efficient whilst not having to be unpacked once retrieved like numbers stored using different amounts of bits would have to be.

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [May 26, 2026, 11:56pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/8 "2026-05-26T23:56:34Z")

</div>

somebody should make a guide on buffers

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [May 26, 2026, 11:56pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/9 "2026-05-26T23:56:37Z")

</div>

img`…` is a buffer, aka making an image in blocks is already a buffer

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [May 26, 2026, 11:56pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/10 "2026-05-26T23:56:40Z")

</div>

base64 isn’t a thing, it’s a type of number

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [May 26, 2026, 11:56pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/11 "2026-05-26T23:56:42Z")

</div>

a buffer contains hexadecimal, so 0123456789ABCDEF

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [May 27, 2026, 12:06am UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/12 "2026-05-27T00:06:01Z")

</div>

That’s a hex (aka hexadecimal) string. Yes, writing `hex`(hex data)`` does automatically turn your hex string into a buffer, but that is still a hex string and not a buffer.

Yes Base64 is a number type but a Base64 encoded string is what we are referring to here.

---

<div class="post-metadata">

**Author:** ![NeverStopTheCoder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/neverstopthecoder/32/21194_2.png) [@NeverStopTheCoder](https://forum.makecode.com/u/NeverStopTheCoder)\
**Post date:** [May 27, 2026, 2:21am UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/13 "2026-05-27T02:21:50Z")

</div>

well I wanted to make a buffer of a image make it into a small code say 65374 and if you type 65374 it gives you that image

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [May 27, 2026, 2:31am UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/14 "2026-05-27T02:31:29Z")

</div>

Images are already stored as hex-strings in MakeCode Arcade. You want a data structure known as a _map_ or a _dictionary_, which are not native to TypeScript but are easy enough to create using interfaces.

```typescript
interface KvPair {
    key: string
    value: Image
}

let dictionary: KvPair[] = []
dictionary.push({key: 'abcde', value: sprites.duck.duck3})
dictionary.push({key: '65374', value: sprites.castle.heroWalkFront1})

let theSprite: Sprite = sprites.create(img`.`, SpriteKind.Player)
let key: string = game.askForString("Enter a key.")

let index: number = -1
for (let i: number = 0; i < dictionary.length; i++) {
    let kv: KvPair = dictionary[i]
    if (kv.key == key) {
        index = i
        break
    }
}

if (index > -1) {
    theSprite.setImage(dictionary[index].value)
} else {
    theSprite.setImage(sprites.food.smallApple)
}

```

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [May 27, 2026, 4:48pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/15 "2026-05-27T16:48:26Z")

</div>

If you are trying to make it generate any image and not just store Images are already stored in a quite space efficient way. Just thinking about it, those numbers would _maybe_ encode a 2x3 image, with limited colors. You have to realize that the number has to be long enough that every possible permutation of the image can be encoded with a different number, so… yeah I’m not doing that math, but my point is that they will have to be very long numbers.

---

<div class="post-metadata">

**Author:** ![NeverStopTheCoder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/neverstopthecoder/32/21194_2.png) [@NeverStopTheCoder](https://forum.makecode.com/u/NeverStopTheCoder)\
**Post date:** [May 28, 2026, 5:46pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/16 "2026-05-28T17:46:01Z")

</div>

I wanted to make a game where I draw a image click something like give code I get something like 542e524w5 and if I type that in I get that image

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [May 28, 2026, 10:25pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/17 "2026-05-28T22:25:41Z")

</div>

Well I suppose you could use the settings extension to do that fairly easily. If you want it to actually be a code representing the image, the code will have to be wayyyy longer. For example, here’s some code I wrote to take in an image and return a base64 encoded string of the image data:

> **[image to base64 and back](https://arcade.makecode.com/S00958-08654-86151-94710)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

For that simple 21 x 21 test image, the string it generated was  
`FRUzMzMzMzMzMzMzNDMzMzMzMzMzM0MzY2ZmM2NmNjMzNDMzNjMzNjMzM0MzM2MzM2MzMzMzNDMzNjMzZjYzM0MzM2MzM2MzMzMzNDMzNjMzNjMzM0MzM2MzM2NmNjMzNDMzMzMzMzMzM0MzMzMzMzMzMzMzNDMzZjYzZmY2M0MzMzYzMzNjMzMzNDNjMzMzMzYzM0MzM2M2MzNjMzMzNDMzMzYzMzYzM0MzMzNjMzNjMzMzNDNjZjMzMzYzM0MzMzMzMzMzMzMzNDMzMzMzMzMzM0NEREREREREREREBA==` which is not a small code to type in. Of course, you can always copy and paste it, but still it would not be nice and simple. The settings route, on the other hand, could let you easily make a menu of all the images you have created, so you wouldn’t even need codes. Images just wouldn’t be shareable across devices unless you also added this base64 string code as an export/import method.

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [May 28, 2026, 10:26pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/18 "2026-05-28T22:26:03Z")

</div>

yes but no? The amount of characters to make it would be a lot. here’s an example:

> **[img -\> text, text -\> img](https://arcade.makecode.com/S06068-83761-34671-83536)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![NeverStopTheCoder](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/neverstopthecoder/32/21194_2.png) [@NeverStopTheCoder](https://forum.makecode.com/u/NeverStopTheCoder)\
**Post date:** [May 29, 2026, 1:54am UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/19 "2026-05-29T01:54:37Z")

</div>

well I get that if I type a string I can be used as a image and be as long as the sprite has pixels but how small can you cram say a 16x16 sprite down into

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [May 29, 2026, 4:54pm UTC](https://forum.makecode.com/t/how-do-buffers-work/44161/20 "2026-05-29T16:54:55Z")

</div>

1 character if you use the settings extension to save it, but unpacked, 16x16 (256 characters, or if the width and height is dynamic, 260 (+4))

[Next page](https://forum.makecode.com/t/how-do-buffers-work/44161.md?page=2)
